Make our parsing of INTERVAL literals spec-compliant (or at least a heck of
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 10 Sep 2008 18:29:41 +0000 (18:29 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 10 Sep 2008 18:29:41 +0000 (18:29 +0000)
commit96b2e298d71672ed1a01908aaa0c2e38ade2a6f9
treeee36a7390bf6e8c71c4c7364164cc97105300ed2
parentd995a86b11dfec1550b900f2fde5392b7fb16be7
Make our parsing of INTERVAL literals spec-compliant (or at least a heck of
a lot closer than it was before).  To do this, tweak coerce_type() to pass
through the typmod information when invoking interval_in() on an UNKNOWN
constant; then fix DecodeInterval to pay attention to the typmod when deciding
how to interpret a units-less integer value.  I changed one or two other
details as well.  I believe the code now reacts as expected by spec for all
the literal syntaxes that are specifically enumerated in the spec.  There
are corner cases involving strings that don't exactly match the set of fields
called out by the typmod, for which we might want to tweak the behavior some
more; but I think this is an area of user friendliness rather than spec
compliance.  There remain some non-compliant details about the SQL syntax
(as opposed to what's inside the literal string); but at least we'll throw
error rather than silently doing the wrong thing in those cases.
src/backend/parser/parse_coerce.c
src/backend/utils/adt/datetime.c
src/backend/utils/adt/nabstime.c
src/backend/utils/adt/timestamp.c
src/include/utils/datetime.h
src/test/regress/expected/interval.out
src/test/regress/sql/interval.sql