From 70530c808bf8eaba2a41a28c9dc7b96dcc3b6c51 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 11 Sep 2008 15:27:30 +0000 Subject: Adjust the parser to accept the typename syntax INTERVAL ... SECOND(n) and the literal syntax INTERVAL 'string' ... SECOND(n), as required by the SQL standard. Our old syntax put (n) directly after INTERVAL, which was a mistake, but will still be accepted for backward compatibility as well as symmetry with the TIMESTAMP cases. Change intervaltypmodout to show it in the spec's way, too. (This could potentially affect clients, if there are any that analyze the typmod of an INTERVAL in any detail.) Also fix interval input to handle 'min:sec.frac' properly; I had overlooked this case in my previous patch. Document the use of the interval fields qualifier, which up to now we had never mentioned in the docs. (I think the omission was intentional because it didn't work per spec; but it does now, or at least close enough to be credible.) --- doc/src/sgml/datatype.sgml | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 48dfe0a9c47..0b969eaa22e 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1,4 +1,4 @@ - + Data Types @@ -131,7 +131,7 @@ - interval [ (p) ] + interval [ fields ] [ (p) ] time span @@ -1420,7 +1420,7 @@ SELECT b, char_length(b) FROM test2; 1 microsecond / 14 digits - interval [ (p) ] + interval [ fields ] [ (p) ] 12 bytes time intervals -178000000 years @@ -1505,6 +1505,30 @@ SELECT b, char_length(b) FROM test2; storage is used, or from 0 to 10 when floating-point storage is used. + + The interval type has an additional option, which is + to restrict the set of stored fields by writing one of these phrases: + + YEAR + MONTH + DAY + HOUR + MINUTE + SECOND + YEAR TO MONTH + DAY TO HOUR + DAY TO MINUTE + DAY TO SECOND + HOUR TO MINUTE + MINUTE TO SECOND + + Input falling outside the specified set of fields is silently discarded. + Note that if both fields and + precision are specified, the + fields must include SECOND, + since the precision applies only to the seconds. + + The type time with time zone is defined by the SQL standard, but the definition exhibits properties which lead to @@ -1928,18 +1952,26 @@ January 8 04:05:06 1999 PST direction can be ago or empty. The at sign (@) is optional noise. The amounts of different units are implicitly added up with appropriate - sign accounting. + sign accounting. ago negates all the fields. Quantities of days, hours, minutes, and seconds can be specified without explicit unit markings. For example, '1 12:59:10' is read - the same as '1 day 12 hours 59 min 10 sec'. + the same as '1 day 12 hours 59 min 10 sec'. Also, + a combination of years and months can be specified with a dash; + for example '200-10' is read the same as '200 years + 10 months'. (These shorter forms are in fact the only ones allowed + by the SQL standard.) - The optional subsecond precision p should - be between 0 and 6, and defaults to the precision of the input literal. + When writing an interval constant with a fields + specification, or when assigning to an interval column that was defined + with a fields specification, the interpretation of + unmarked quantities depends on the fields. For + example INTERVAL '1' YEAR is read as 1 year, whereas + INTERVAL '1' means 1 second. -- cgit v1.2.3