![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Of course, I can just create three numeric fields (month, day, year). But, what is the "best" way to ensure the contents of that *set* of fields makes sense? E.g., the month is constrained to [1..12], day constrained to a value determined by month (and year), etc. Should I just define triggers for each that examine their counterparts for validity checks, etc.? |
#3
| |||
| |||
|
|
Hi, I need to store "dates" -- but, with the capability of leaving portions as "unknown". The easiest example I can think of to illustrate this would be tracking birthdates -- often you will know the month+day but not the *year*. Or, even just a month and a year (based on knowing current *age*). Of course, I can just create three numeric fields (month, day, year). But, what is the "best" way to ensure the contents of that *set* of fields makes sense? E.g., the month is constrained to [1..12], day constrained to a value determined by month (and year), etc. Should I just define triggers for each that examine their counterparts for validity checks, etc.? Or, define a new *type* that implicitly does this sort of thing? (note the consequences of each approach when it comes to sorting, etc.) |
#4
| |||
| |||
|
|
The easiest example I can think of to illustrate this would be tracking birthdates -- often you will know the month+day but not the *year*. Or, even just a month and a year (based on knowing current *age*). |
#5
| |||
| |||
|
|
On Thu, 17 Feb 2011 22:17:49 -0700, D Yuniskis wrote: The easiest example I can think of to illustrate this would be tracking birthdates -- often you will know the month+day but not the *year*. Or, even just a month and a year (based on knowing current *age*). You can use interval types. They're created for just that situation. The description is here: http://www.postgresql.org/docs/9.0/s...-datetime.html |
#6
| |||
| |||
|
|
D Yuniskis, 18.02.2011 06:17: Hi, I need to store "dates" -- but, with the capability of leaving portions as "unknown". The easiest example I can think of to illustrate this would be tracking birthdates -- often you will know the month+day but not the *year*. Or, even just a month and a year (based on knowing current *age*). Of course, I can just create three numeric fields (month, day, year). But, what is the "best" way to ensure the contents of that *set* of fields makes sense? E.g., the month is constrained to [1..12], day constrained to a value determined by month (and year), etc. Should I just define triggers for each that examine their counterparts for validity checks, etc.? Or, define a new *type* that implicitly does this sort of thing? (note the consequences of each approach when it comes to sorting, etc.) I wonder if you could use a combination of a date field and flags to indicate if part of the date is valid. So you'd have the columns: the_date date month_valid boolean year_valid boolean day_valid boolean So if you just know the year and month, you use 2011-02-01 and set day_valid = false If you just know the day and month you use 1900-04-14 and set year_valid = false |
|
Not sure how complicated this would be to use though, but at least you can the automatic date checking without any further problems. A problem would be a February 29th (when only getting day and month) |
#7
| |||
| |||
|
|
A problem would be a February 29th (when only getting day and month) Or, "October 5" when the year is omitted. |
#8
| |||
| |||
|
|
D Yuniskis wrote on 18.02.2011 22:12: A problem would be a February 29th (when only getting day and month) Or, "October 5" when the year is omitted. October 5 is not a problem with my solution as that is valid for any year, whereas February 29th is only valid every 4 years. |
![]() |
| Thread Tools | |
| Display Modes | |
| |