Commit Graph

102 Commits

Author SHA1 Message Date
Tom Lane 0de45c1c27 Add timestamp-versus-timestamptz cross-type comparison functions,
flesh out the index operator classes to include these.  In passing,
fix erroneous volatility marking of ACL functions.
2004-03-22 01:38:18 +00:00
Tom Lane 1bc2d544b9 Localize our dependencies on the way to create NAN or INFINITY.
Per recent proposal to pghackers.
2004-03-15 03:29:22 +00:00
Bruce Momjian 1973971821 Per a brief conversation with Tom, I've created a patch for adding
support for 'week' within the date_trunc function.

Within the patch I added a couple of test cases and associated target
output, and changed the documentation to add 'week' appropriately.

Robert Creager
2004-03-05 02:41:14 +00:00
Tom Lane a9e08392dd Create crosstype comparison operators for date vs. timestamp and date
vs. timestamptz.  This allows use of indexes for expressions like
  datecol >= date 'today' - interval '1 month'
which were formerly not indexable without casting the righthand side
down from timestamp to date.
2004-02-14 20:16:18 +00:00
Bruce Momjian 1c757c49fa > > I have no idea if this in Oracle or not. But it's something I
> > needed, and other people in the past asked about it too.
>
> It is in Oracle, but you aren't exactly on the spot.  It should be
>
> IYYY - 4 digits  ('2003')
> IYY  - 3 digits  ('003')
> IY   - 2 digits  ('03')
> I    - 1 digit   ('3')

Here is an updated patch that does that.

Kurt Roeckx
2003-12-25 03:36:24 +00:00
PostgreSQL Daemon 969685ad44 $Header: -> $PostgreSQL Changes ... 2003-11-29 19:52:15 +00:00
Peter Eisentraut 7438af96fa More message editing, some suggested by Alvaro Herrera 2003-09-29 00:05:25 +00:00
Peter Eisentraut feb4f44d29 Message editing: remove gratuitous variations in message wording, standardize
terms, add some clarifications, fix some untranslatable attempts at dynamic
message building.
2003-09-25 06:58:07 +00:00
Tom Lane d1031cdef2 Adjust date/time input parsing code to correctly distinguish the four
SQLSTATE error codes required by SQL99 (invalid format, datetime field
overflow, interval field overflow, invalid time zone displacement value).
Also emit a HINT about DateStyle in cases where it seems appropriate.
Per recent gripes.
2003-08-27 23:29:29 +00:00
Bruce Momjian 147c16497b Call it Linux, not GNU/Linux. 2003-08-26 21:31:11 +00:00
Bruce Momjian 46785776c4 Another pgindent run with updated typedefs. 2003-08-08 21:42:59 +00:00
Tom Lane f2b6bb42ab Fix floating-point timestamp comparisons to not go nuts if NaN is
encountered; per bug report from Christian van der Leeden 8/7/03.
Also, adjust larger/smaller routines (MAX/MIN) to share code with
comparisons for timestamp, interval, timetz.
2003-08-08 00:10:31 +00:00
Bruce Momjian f3c3deb7d0 Update copyrights to 2003. 2003-08-04 02:40:20 +00:00
Bruce Momjian 089003fb46 pgindent run. 2003-08-04 00:43:34 +00:00
Tom Lane b6a1d25b0a Error message editing in utils/adt. Again thanks to Joe Conway for doing
the bulk of the heavy lifting ...
2003-07-27 04:53:12 +00:00
Bruce Momjian 74ca686796 I corecting date_trunc('quarter',...) and friends because orig version
doing '2003-07-30' -> '2003-04-01', '2003-11-30' ->'2003-07-01'

B?jthe Zolt?n
2003-07-26 15:17:36 +00:00
Tom Lane 764f72dc82 Make EXTRACT(TIMEZONE) and SET/SHOW TIMEZONE follow the SQL convention
for the sign of timezone offsets, ie, positive is east from UTC.  These
were previously out of step with other operations that accept or show
timezones, such as I/O of timestamptz values.
2003-07-17 00:55:37 +00:00
Tom Lane 841b4a2d55 tm2timestamp should return -1, not elog, on overflow. (In the backend
this is merely an API inconsistency, but in ecpg it's fatal.)  Also,
fix misconceived overflow test in HAVE_INT64_TIMESTAMP case.
2003-07-04 18:21:14 +00:00
Tom Lane 30f609484d Add binary I/O routines for a bunch more datatypes. Still a few to go,
but that was enough tedium for one day.  Along the way, move the few
support routines for types xid and cid into a more logical place.
2003-05-12 23:08:52 +00:00
Tom Lane afe1185cf0 Remove unnecessary dt2local() call. 2003-04-07 15:04:03 +00:00
Tom Lane d685417fbb Avoid repeated computation of the constants date2j(1970, 1, 1) and
date2j(2000, 1, 1).  Should make for some marginal speed improvement
in date/time operations.
2003-04-04 04:50:44 +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
Tom Lane 31e69ccb21 Add explicit tests for division by zero to all user-accessible integer
division and modulo functions, to avoid problems on OS X (which fails to
trap 0 divide at all) and Windows (which traps it in some bizarre
nonstandard fashion).  Standardize on 'division by zero' as the one true
spelling of this error message.  Add regression tests as suggested by
Neil Conway.
2003-03-11 21:01:33 +00:00
Tom Lane 191ef2b407 Change EXTRACT(EPOCH FROM timestamp) so that a timestamp without time zone
is assumed to be in local time, not GMT.  This improves consistency with
other operations, which all assume local timezone when it matters.  Per
bug #897.
2003-02-27 21:36:58 +00:00
Tom Lane 80d6a277c9 Simplify timezone-handling code per proposal to pghackers: get rid of
setting timezone-related variables during transaction start.  They were
not used anyway in platforms that HAVE_TM_ZONE or HAVE_INT_TIMEZONE,
which it appears is *all* the platforms we are currently supporting.
For platforms that have neither, we now only support UTC or numeric-
offset-from-UTC timezones.
2003-02-22 05:57:45 +00:00
Tom Lane b3d7af46a9 Fix sloppy comment. 2003-01-22 20:44:20 +00:00
Tom Lane fb715e05f5 Repair inconsistent rounding behavior for timestamp, time, interval,
per gripe from Csaba Nagy.  There is still potential for platform-specific
behavior for values that are exactly halfway between integers, but at
least we now get the expected answer for all other cases.
2003-01-09 01:06:57 +00:00
Tom Lane 5eb6de5991 Remove NO_MKTIME_BEFORE_1970. I had speculated that it was not needed
anymore given the mktime() workaround now done in DetermineLocalTimeZone.
This has now been confirmed by Robert Bruccoleri for Irix, and I'm going
to extrapolate to AIX as well.
2002-11-12 00:39:08 +00:00
Tom Lane e303a2dbe8 Add last-ditch defense against attempts to compile datetime code with
-ffast-math.
2002-09-21 19:52:41 +00:00
Bruce Momjian e50f52a074 pgindent run. 2002-09-04 20:31:48 +00:00
Tom Lane b3506006b5 EXTRACT(EPOCH FROM timestamp) gave wrong answers in the int64-timestamp
case for timestamptz input, and differently wrong answers in the float-
timestamp case for timestamp input.
2002-09-03 22:55:54 +00:00
Bruce Momjian 97ac103289 Remove sys/types.h in files that include postgres.h, and hence c.h,
because c.h has sys/types.h.
2002-09-02 02:47:07 +00:00
Tom Lane 5cabcfccce Modify array operations to include array's element type OID in the
array header, and to compute sizing and alignment of array elements
the same way normal tuple access operations do --- viz, using the
tupmacs.h macros att_addlength and att_align.  This makes the world
safe for arrays of cstrings or intervals, and should make it much
easier to write array-type-polymorphic functions; as examples see
the cleanups of array_out and contrib/array_iterator.  By Joe Conway
and Tom Lane.
2002-08-26 17:54:02 +00:00
Thomas G. Lockhart b71310d8e0 Add guard code to protect from buffer overruns on long date/time input
strings. Should go back in and look at doing this a bit more elegantly
 and (hopefully) cheaper. Probably not too bad anyway, but it seems a
 shame to scan the strings twice: once for length for this buffer overrun
 protection, and once to parse the line.
Remove use of pow() in date/time handling; was already gone from everything
 *but* the time data types.
Define macros for handling typmod manipulation for date/time types.
 Should be more robust than all of that brute-force inline code.
Rename macros for masking and typmod manipulation to put TIMESTAMP_
 or INTERVAL_ in front of the macro name, to reduce the possibility
 of name space collisions.
2002-08-04 06:44:47 +00:00
Bruce Momjian d84fe82230 Update copyright to 2002. 2002-06-20 20:29:54 +00:00
Thomas G. Lockhart cc2ce83633 Fix lookup tables used for rounding interval data values when not using
integer datetimes. Thanks to Tom Lane for spotting the problem.
2002-05-14 13:37:27 +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
Tom Lane c422b5ca6b Code review for improved-hashing patch. Fix some portability issues
(char != unsigned char, Datum != uint32); make use of new hash code in
dynahash hash tables and hash joins.
2002-03-09 17:35:37 +00:00
Bruce Momjian 92288a1cf9 Change made to elog:
o  Change all current CVS messages of NOTICE to WARNING.  We were going
to do this just before 7.3 beta but it has to be done now, as you will
see below.

o Change current INFO messages that should be controlled by
client_min_messages to NOTICE.

o Force remaining INFO messages, like from EXPLAIN, VACUUM VERBOSE, etc.
to always go to the client.

o Remove INFO from the client_min_messages options and add NOTICE.

Seems we do need three non-ERROR elog levels to handle the various
behaviors we need for these messages.

Regression passed.
2002-03-06 06:10:59 +00:00
Tatsuo Ishii 3382fbb60d Fix bug in extract/date_part for milliseconds/miscroseconds and
timestamp/timestamptz combo. Now extract/date_part returns
seconds*1000 or 1000000 + fraction part as the manual stats.
regression test are also fixed.

See the thread in pgsql-hackers:

Subject: Re: [HACKERS] timestamp_part() bug?
Date: Sat, 02 Mar 2002 11:29:53 +0900
2002-03-04 03:55:50 +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
Thomas G. Lockhart b5e23db438 Rework the date/time parsing to tighten up some cases and to enable other
cases which should have worked but did not.
Now supports julian day (J2452271), ISO time labels (T040506) and various
 combinations of spaces and run-togethers of dates, times, and time zones.
All regression tests pass, and I have more tests to add after the 7.2
 release (don't want to require changes to the ancillary horology result
 files until after then).
2001-12-29 18:31:48 +00:00
Tom Lane dcdf9119a8 Tweak interval_avg support to avoid coredump with Alpha/Tru64 compiler.
Per report from Bernd Tegge.
2001-11-21 18:29:48 +00:00
Bruce Momjian b81844b173 pgindent run on all C files. Java run to follow. initdb/regression
tests pass.
2001-10-25 05:50:21 +00:00
Thomas G. Lockhart 424d9389d6 Fix transposed arguments for typmod for one INTERVAL production.
Mask both typmod subfields for INTERVAL to avoid setting the high bit,
 per dire warning from Tom Lane.
Clear tmask for DTK_ISO_TIME case to avoid time zone troubles.
 Symptom reported by Tom Lane.
Clean up checking for valid time zone info in output routine.
 This should now work for both SQL99 and Unix-style time zones.
Put in explicit check for INTERVAL() typmod rounding to avoid accumulating
 cruft in the lower bits. Not sure that this helps, but we'll need to do
 something. The symptom is visible with a query like
 select interval(2) '10000 days 01:02:03.040506';
Regression tests are patched to repair the Tom Lane symptom, and all pass.
2001-10-20 01:02:22 +00:00
Tom Lane f9b6583747 Didn't compile on non-HAVE_TM_ZONE machines. 2001-10-18 19:54:59 +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 7547b0104a Define CEST as a synonym for Central European Savings Time
per Jan Varga <varga@utcru.sk>
Fix up spacing and formatting.
2001-10-05 06:38:59 +00:00
Tom Lane 64dff0beac Fix some problems in new variable-resolution-timestamp code. 2001-10-04 14:49:57 +00:00
Tom Lane 77be5f9451 AdjustTimestampForTypmod does not work (at least not portably) on
-infinity and +infinity.  Put TIMESTAMP_NOT_FINITE guard into the routine,
instead of forgetting it at some call sites.  Fixes regression test
failures here.
2001-10-03 15:50:48 +00:00