Commit Graph

43 Commits

Author SHA1 Message Date
Tom Lane 9a8f5729b4 Fix to_timestamp/to_date's handling of consecutive spaces in format string.
When there are consecutive spaces (or other non-format-code characters) in
the format, we should advance over exactly that many characters of input.
The previous coding mistakenly did a "skip whitespace" action between such
characters, possibly allowing more input to be skipped than the user
intended.  We only need to skip whitespace just before an actual field.

This is really a bug fix, but given the minimal number of field complaints
and the risk of breaking applications coded to expect the old behavior,
let's not back-patch it.

Jeevan Chalke
2014-01-20 13:45:51 -05:00
Tom Lane 631dc390f4 Fix some odd behaviors when using a SQL-style simple GMT offset timezone.
Formerly, when using a SQL-spec timezone setting with a fixed GMT offset
(called a "brute force" timezone in the code), the session_timezone
variable was not updated to match the nominal timezone; rather, all code
was expected to ignore session_timezone if HasCTZSet was true.  This is
of course obviously fragile, though a search of the code finds only
timeofday() failing to honor the rule.  A bigger problem was that
DetermineTimeZoneOffset() supposed that if its pg_tz parameter was
pointer-equal to session_timezone, then HasCTZSet should override the
parameter.  This would cause datetime input containing an explicit zone
name to be treated as referencing the brute-force zone instead, if the
zone name happened to match the session timezone that had prevailed
before installing the brute-force zone setting (as reported in bug #8572).
The same malady could affect AT TIME ZONE operators.

To fix, set up session_timezone so that it matches the brute-force zone
specification, which we can do using the POSIX timezone definition syntax
"<abbrev>offset", and get rid of the bogus lookaside check in
DetermineTimeZoneOffset().  Aside from fixing the erroneous behavior in
datetime parsing and AT TIME ZONE, this will cause the timeofday() function
to print its result in the user-requested time zone rather than some
previously-set zone.  It might also affect results in third-party
extensions, if there are any that make use of session_timezone without
considering HasCTZSet, but in all cases the new behavior should be saner
than before.

Back-patch to all supported branches.
2013-11-01 12:13:18 -04:00
Tom Lane f62be400c0 On second thought, we'd better just drop these tests altogether.
Further experimentation reveals that my previous change didn't fix the
issue entirely: these tests would still fail at the spring-forward DST
transition.  There doesn't seem to be any great value in testing this
specific issue for both timestamp and timestamptz, so just lose the
latter tests.
2011-11-06 20:12:20 -05:00
Tom Lane 362f731dde Un-break horology regression test.
Adjust ill-considered timezone-dependent tests added in commit
8a3d33c8e6 so that they won't fail on DST
transition days.  Per all-pink buildfarm.
2011-11-06 18:20:26 -05:00
Robert Haas 8a3d33c8e6 Fix parsing of time string followed by yesterday/today/tomorrow.
Previously, 'yesterday 04:00:00'::timestamp didn't do the same thing as
'04:00:00 yesterday'::timestamp, and the return value from the latter
was midnight rather than the specified time.

Dean Rasheed, with some stylistic changes
2011-08-30 11:38:42 -04:00
Tom Lane 9aae81527f Re-allow input of Julian dates prior to 0001-01-01 AD.
This was unintentionally broken in 8.4 while tightening up checking of
ordinary non-Julian date inputs to forbid references to "year zero".
Per bug #5672 from Benjamin Gigot.
2010-09-22 23:48:07 -04:00
Tom Lane 3f1e529e78 Make to_timestamp and friends skip leading spaces before an integer field,
even when not in FM mode.  This improves compatibility with Oracle and with
our pre-8.4 behavior, as per bug #4862.

Brendan Jurd

Add a couple of regression test cases for this.  In passing, get rid of the
labeling of the individual test cases; doesn't seem to be good for anything
except causing extra work when inserting a test...

Tom Lane
2009-06-22 17:54:30 +00:00
Bruce Momjian 65b731bd9d Fix to_timestamp() to not require upper/lower case matching for meridian
designations (AM/PM).  Also separate out matching of a meridian with
periods (e.g. A.M.) and with those without.

Do the same for AD/BC.

Brendan Jurd
2009-02-07 14:16:46 +00:00
Tom Lane 06edce4c3f Tighten up to_date/to_timestamp so that they are more likely to reject
erroneous input, rather than silently producing bizarre results as formerly
happened.

Brendan Jurd
2008-09-11 17:32:34 +00:00
Tom Lane 3eb98fd165 Adjust horology test to avoid join-plan-dependent result ordering in
a few queries.  Should fix buildfarm failures arising from new,
more aggressive autovac settings.
2007-07-25 17:22:37 +00:00
Tom Lane d8b5c95ca8 Remove hard-wired lists of timezone abbreviations in favor of providing
configuration files that can be altered by a DBA.  The australian_timezones
GUC setting disappears, replaced by a timezone_abbreviations setting (set this
to 'Australia' to get the effect of australian_timezones).  The list of zone
names defined by default has undergone a bit of cleanup, too.  Documentation
still needs some work --- in particular, should we fix Table B-4, or just get
rid of it?  Joachim Wieland, with some editorializing by moi.
2006-07-25 03:51:23 +00:00
Tom Lane 23a1f015e5 Adjust interval-addition test so that it won't fail on DST transition days.
Strange that we missed this DST dependence while fixing the others.
2006-04-02 19:39:54 +00:00
Bruce Momjian b2b6548c79 Please find attached diffs for documentation and simple regression
tests for the new interval->day changes. I added tests for
justify_hours() and justify_days() to interval.sql, as they take
interval input and produce interval output. If there's a more
appropriate place for them, please let me know.

Michael Glaesemann
2005-07-30 14:52:04 +00:00
Neil Conway f5ab0a14ea Add a "USING" clause to DELETE, which is equivalent to the FROM clause
in UPDATE. We also now issue a NOTICE if a query has _any_ implicit
range table entries -- in the past, we would only warn about implicit
RTEs in SELECTs with at least one explicit RTE.

As a result of the warning change, 25 of the regression tests had to
be updated. I also took the opportunity to remove some bogus whitespace
differences between some of the float4 and float8 variants. I believe
I have correctly updated all the platform-specific variants, but let
me know if that's not the case.

Original patch for DELETE ... USING from Euler Taveira de Oliveira,
reworked by Neil Conway.
2005-04-07 01:51:41 +00:00
Tom Lane e34082ee3b Add missing operators of the form interval-plus-datetime, as required for
better SQL compliance in this area, per recent discussion.  Mark related
operators as commutators where possible.  (The system doesn't actually care
about commutator marking for operators not returning boolean, at the moment,
but this seems forward-thinking and besides it made it easier to verify
that we hadn't missed any.)
Also, remove interval-minus-time and interval-minus-timetz operators.
I'm not sure how these got in, but they are nonstandard and had very
obviously broken behavior.  (minus is not commutative in anyone's book.)
I doubt anyone had ever used 'em, because we'd surely have gotten a bug
report about it if so.
2004-07-02 22:50:23 +00:00
Tom Lane 9c2a7c2269 Apply (a somewhat revised version of) Greg Mullane's patch to eliminate
heuristic determination of day vs month in date/time input.  Add the
ability to specify that input is interpreted as yy-mm-dd order (which
formerly worked, but only for yy greater than 31).  DateStyle's input
component now has the preferred spellings DMY, MDY, or YMD; the older
keywords European and US are now aliases for the first two of these.
Per recent discussions on pgsql-general.
2003-07-29 00:03:19 +00:00
Bruce Momjian d7f10705b4 Attached is a patch that limits the range tested by horology to
what is capable using integer-datatime timestamps. It does attempt
to exercise the maximum allowable timestamp range.
Also is a small error check when converting a timestamp from external
to internal format that prevents out of range timestamps from being
entered.

Files patched:
        Index: src/backend/utils/adt/timestamp.c
                Added range check to prevent out of range timestamps
                from being used.

        Index: src/test/regress/sql/horology.sql
        Index: src/test/regress/expected/horology-no-DST-before-1970.out
        Index: src/test/regress/expected/horology-solaris-1947.out
                Limited range of timestamps being checked to
                Jan 1, 4713 BC  to Dec 31, 294276

In creating this patch, I have seen some definite problems with integer
timestamps and how they react when used near their limits. For example,
the following statement gives the correct result:

        SELECT timestamp without time zone 'Jan 1, 4713 BC'
               + interval '109203489 days' AS "Dec 31, 294276";

However, this statement which is the logical inverse of the above
gives incorrect results:

        SELECT timestamp without time zone '12/31/294276'
             - timestamp without time zone 'Jan 1, 4713 BC' AS "109203489 Days";

John Cochran
2003-03-20 06:03:00 +00:00
Bruce Momjian a286f73210 The following patches eliminate the overflows in the j2date() and date2j()
functions which limited the maximum date for a timestamp to AD 1465001.
The new limit is AD 5874897.
The files affected are:

doc/src/sgml/datatype.sgml:
    Documentation change due to patch. Included is a notice about
    the reduced range when using an eight-byte integer for timestamps.

src/backend/utils/adt/datetime.c:
    Replacement functions for j2date() and date2j() functions.

src/include/utils/datetime.h:
    Corrected a bug with the limit on the earliest possible date,
    Nov 23,-4713 has a Julian day count of -1. The earliest possible
    date should be Nov 24, -4713 with a day count of 0.

src/test/regress/expected/horology-no-DST-before-1970.out:
src/test/regress/expected/horology-solaris-1947.out:
src/test/regress/expected/horology.out:
    Copies of expected output for regression testing.
    Note: Only horology.out has been physically tested. I do not have access
    to a Solaris box and I don't know how to provoke the "pre-1970" test.

src/test/regress/sql/horology.sql:
    Added some test cases to check extended range.

John Cochran
2003-02-19 03:48:11 +00:00
Tom Lane bd96dd1184 Allow a time zone to be specified (and silently ignored) in the input
for type 'time without time zone', as we already did for type
'timestamp without time zone'.  This patch was proposed by Tom Lockhart
on 7-Nov-02, but he never got around to applying it.  Adjust regression
tests and documentation to match.
2003-01-31 01:08:08 +00:00
Tom Lane b26dfb9522 Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution.  Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 21:35:25 +00:00
Thomas G. Lockhart 547df0cc85 Support alternate storage scheme of 64-bit integer for date/time types.
Use "--enable-integer-datetimes" in configuration to use this rather
 than the original float8 storage. I would recommend the integer-based
 storage for any platform on which it is available. We perhaps should
 make this the default for the production release.
Change timezone(timestamptz) results to return timestamp rather than
 a character string. Formerly, we didn't have a way to represent
 timestamps with an explicit time zone other than freezing the info into
 a string. Now, we can reasonably omit the explicit time zone from the
 result and return a timestamp with values appropriate for the specified
 time zone. Much cleaner, and if you need the time zone in the result
 you can put it into a character string pretty easily anyway.
Allow fractional seconds in date/time types even for dates prior to 1BC.
Limit timestamp data types to 6 decimal places of precision. Just right
 for a micro-second storage of int8 date/time types, and reduces the
 number of places ad-hoc rounding was occuring for the float8-based types.
Use lookup tables for precision/rounding calculations for timestamp and
 interval types.  Formerly used pow() to calculate the desired value but
 with a more limited range there is no reason to not type in a lookup
 table. Should be *much* better performance, though formerly there were
 some optimizations to help minimize the number of times pow() was called.
Define a HAVE_INT64_TIMESTAMP variable. Based on the configure option
 "--enable-integer-datetimes" and the existing internal INT64_IS_BUSTED.
Add explicit date/interval operators and functions for addition and
 subtraction. Formerly relied on implicit type promotion from date to
 timestamp with time zone.
Change timezone conversion functions for the timetz type from "timetz()"
 to "timezone()". This is consistant with other time zone coersion
 functions for other types.
Bump the catalog version to 200204201.
Fix up regression tests to reflect changes in fractional seconds
 representation for date/times in BC eras.
All regression tests pass on my Linux box.
2002-04-21 19:52:18 +00:00
Thomas G. Lockhart 192061e45b Repair bugs in declarations of routines to add timestamptz and interval.
Thanks to Bruce for spotting it and Tom Lane for diagnosing it.
Since horology test output is changing anyway, add some date/time input
 tests to horology.sql. Some of these should move to the tests for the
 individual data types, and we perhaps should add an entire new test
 for "timezone" to allow manipulating the current time zone without
 risking damage to the results of other tests.
2002-01-12 04:38:38 +00:00
Tom Lane 52ca149b36 Update regress tests to reflect removal of 'current'. 2001-11-21 18:27:25 +00:00
Thomas G. Lockhart d2ff7e509c Fix last (?) problem with sensitivity to daylight savings time status
when running the regression test. Reported by Tom Lane.
2001-11-06 16:31:13 +00:00
Thomas G. Lockhart 9310075a13 Accept an INTERVAL argument for SET TIME ZONE per SQL99.
Modified the parser and the SET handlers to use full Node structures
 rather than simply a character string argument.
Implement INTERVAL() YEAR TO MONTH (etc) syntax per SQL99.
 Does not yet accept the goofy string format that goes along with, but
 this should be fairly straight forward to fix now as a bug or later
 as a feature.
Implement precision for the INTERVAL() type.
 Use the typmod mechanism for both of INTERVAL features.
Fix the INTERVAL syntax in the parser:
 opt_interval was in the wrong place.
INTERVAL is now a reserved word, otherwise we get reduce/reduce errors.
Implement an explicit date_part() function for TIMETZ.
 Should fix coersion problem with INTERVAL reported by Peter E.
Fix up some error messages for date/time types.
 Use all caps for type names within message.
Fix recently introduced side-effect bug disabling 'epoch' as a recognized
 field for date_part() etc. Reported by Peter E. (??)
Bump catalog version number.
Rename "microseconds" current transaction time field
 from ...Msec to ...Usec. Duh!
date/time regression tests updated for reference platform, but a few
 changes will be necessary for others.
2001-10-18 17:30:21 +00:00
Thomas G. Lockhart 3e1beda2cd Implement precision support for timestamp and time, both with and without
time zones.
SQL99 spec requires a default of zero (round to seconds) which is set
 in gram.y as typmod is set in the parse tree. We *could* change to a
 default of either 6 (for internal compatibility with previous versions)
 or 2 (for external compatibility with previous versions).
Evaluate entries in pg_proc wrt the iscachable attribute for timestamp and
 other date/time types. Try to recognize cases where side effects like the
 current time zone setting may have an effect on results to decide whether
 something is cachable or not.
2001-10-03 05:29:27 +00:00
Tom Lane 6fdf7bed60 Fixes for datetime-related regress tests, from Tom Lockhart. 2001-09-29 15:17:42 +00:00
Thomas G. Lockhart 1f075a32ee Add separate regression tests for timetz and the new timestamptz type.
Modify the timestamp test to reflect the "no time zone" behavior of this
 new code; timestamptz resembles the old timestamp code.
2001-09-28 08:00:11 +00:00
Bruce Momjian 7dac778561 Add GUC setting for Australian timezones. Uses new GUC boolean callback
functions to clear date cache.  Allow regression tests to pass when
timezone set.
2001-06-18 16:14:44 +00:00
Thomas G. Lockhart 9c3bbf256b Alter the previous test for "time with time zone" implicit time zone
(which failed miserably during DST) to just compare against a time
 derived from a timestamp value.
Certainly not a direct check for a correct result, but should work
 at any time of year.
2001-04-06 05:50:29 +00:00
Tom Lane 71d578ab68 Remove daylight-savings-time-dependent tests of 'time with time zone'
datatype.  Perhaps someday we can figure out a way of getting reproducible
results from testing this type, but for now ...
2001-04-04 20:03:11 +00:00
Thomas G. Lockhart 6969b8fa11 Repair usage of the OVERLAPS operator.
Allow some operator-like tokens to be used as function names.
Flesh out support for time, timetz, and interval operators
 and interactions.
Regression tests pass, but non-reference-platform horology test results
 will need to be updated.
2000-12-03 14:51:12 +00:00
Thomas G. Lockhart 6d9299e1fc Move a few specific tests to isolate homogenous type tests into
regression tests for specific types, and move a few others to the
 cross-type "horology" test.
Rearrange the test order slightly, and move the abstime test to the
 "parallel safe" area.
Hand-patch the results for "1947" and for "solaris", so those may not
 be exactly correct.
2000-09-14 15:55:07 +00:00
Thomas G. Lockhart 0d93504c40 Add regression tests for date, time, and time with time zone types.
Modify date->timestamp conversion to use mktime().
 This should do better than before around Daylight Savings Time
 transitions.
2000-09-12 05:42:20 +00:00
Tom Lane 6a4b7d83f3 Tweak horology regress test to ensure platform-independent ordering of
results in conversions tests.  Update horology-no-DST-before-1970.out.
2000-03-16 17:03:41 +00:00
Thomas G. Lockhart 9e7166096e Support full POSIX-style time zone: EST+3, PST-3, etc.
We probably support a superset of the spec, but I don't have the spec
 to confirm this.
Update regression tests to include tests for this format.
2000-03-16 14:38:42 +00:00
Bruce Momjian 2a55934926 Remove SHOW after datestyle reset. 2000-03-09 17:39:34 +00:00
Thomas G. Lockhart 8997675c4b All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
 Transform datetime and timespan into timestamp and interval.
 Deprecate datetime and timespan, though translate to new types in gram.y.
 Transform all datetime and timespan catalog entries into new types.
 Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
 Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
  routines for all date/time types.
 date.{h,c} now deals with date, time types.
 timestamp.{h,c} now deals with timestamp, interval types.
 nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 17:27:27 +00:00
Thomas G. Lockhart 4c4e68dccc Clean up format of tests.
Remove older "::" type coersion syntax in favor of extended SQL92 style.
Include a few new tests for datetime/timespan arithmetic.
2000-01-05 06:07:58 +00:00
Thomas G. Lockhart 8bb569105a Change ORDER BY to get consistant results with new sorting routines. 1997-09-20 16:34:08 +00:00
Thomas G. Lockhart 48b5432769 Include tests for DateStyle output format variations. 1997-07-01 00:34:34 +00:00
Thomas G. Lockhart 89abee4691 Test the "SET DateStyle TO..." date formatting modes. 1997-06-23 15:05:52 +00:00
Thomas G. Lockhart 83b8cf5b6b Add inter-type regression tests for geometry, date/time, and numbers.
Add regression tests for circles, line segments, and paths.
Modify regression tests to allow GEQ optimizer (order results).
1997-05-11 15:42:09 +00:00