aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/timestamp.c
Commit message (Collapse)AuthorAge
...
* Use macros for time-based constants, rather than constants.Bruce Momjian2011-03-12
|
* Stamp copyrights for year 2011.Bruce Momjian2011-01-01
|
* Remove cvs keywords from all files.Magnus Hagander2010-09-20
|
* pgindent run for 9.0Bruce Momjian2010-02-26
|
* Update copyright for the year 2010.Bruce Momjian2010-01-02
|
* interval_abs():Bruce Momjian2009-11-10
| | | | | | | | Add C comment about why there is no interval_abs(): it is unclear what value to return: http://archives.postgresql.org/pgsql-general/2009-10/msg01031.php http://archives.postgresql.org/pgsql-general/2009-11/msg00041.php
* Tigthen binary receive functions so that they reject values that the textHeikki Linnakangas2009-09-04
| | | | | | | | | input functions don't accept either. While the backend can handle such values fine, they can cause trouble in clients and in pg_dump/restore. This is followup to the original issue on time datatype reported by Andrew McNamara a while ago. Like that one, none of these seem worth back-patching.
* Use floor() not rint() when reducing precision of fractional seconds inTom Lane2009-07-06
| | | | | | | | | | timestamp_trunc, timestamptz_trunc, and interval_trunc(). This change only affects the float-datetime case; the integer-datetime case already behaved like truncation instead of rounding. Per gripe from Mario Splivalo. This is a pre-existing issue but I'm choosing not to backpatch, because it's such a corner case and there have not been prior complaints. The issue is largely moot anyway given the trend towards integer datetimes.
* 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef listBruce Momjian2009-06-11
| | | | provided by Andrew.
* Change AdjustIntervalForTypmod to not discard higher-order field values on theTom Lane2009-06-01
| | | | | | | | | | | | | | | | | | | | | | | | | | grounds that they don't fit into the specified interval qualifier (typmod). This behavior, while of long standing, is clearly wrong per spec --- for example the value INTERVAL '999' SECOND means 999 seconds and should not be reduced to less than 60 seconds. In some cases there could be grounds to raise an error if higher-order field values are not given as zero; for example '1 year 1 month'::INTERVAL MONTH should arguably be taken as an error rather than equivalent to 13 months. However our internal representation doesn't allow us to do that in a fashion that would consistently reject all and only the cases that a strict reading of the spec would suggest. Also, seeing that for example INTERVAL '13' MONTH will print out as '1 year 1 mon', we have to be careful not to create a situation where valid data will fail to dump and reload. The present patch therefore takes the attitude of not throwing an error in any such case. We might want to revisit that in future but it would take more redesign than seems prudent in late beta. Per a complaint from Sebastien Flaesch and subsequent discussion. While at other times we might have just postponed such an issue to the next development cycle, 8.4 already has changed the parsing of interval literals quite a bit in an effort to accept all spec-compliant cases correctly. This seems like a change that should be part of that rather than coming along later.
* Remove the useless and rather inconsistent return values of EncodeDateOnly,Tom Lane2009-05-26
| | | | | EncodeTimeOnly, EncodeDateTime, EncodeInterval. These don't have any good reason to fail, and their callers were mostly not checking anyway.
* Rewrite interval_hash() so that the hashcodes are equal for values thatTom Lane2009-04-04
| | | | | | | | | | | | | | | interval_eq() considers equal. I'm not sure how that fundamental requirement escaped us through multiple revisions of this hash function, but there it is; it's been wrong since interval_hash was first written for PG 7.1. Per bug #4748 from Roman Kononov. Backpatch to all supported releases. This patch changes the contents of hash indexes for interval columns. That's no particular problem for PG 8.4, since we've broken on-disk compatibility of hash indexes already; but it will require a migration warning note in the next minor releases of all existing branches: "if you have any hash indexes on columns of type interval, REINDEX them after updating".
* Clean up the code for to_timestamp's conversion of year plus ISO day numberTom Lane2009-03-15
| | | | | | | | | | | | to date, as per bug #4702 and subsequent discussion. In particular, make it work for years specified using AD/BC or CC fields, and fix the test for "no year specified" so that it doesn't trigger inappropriately for 1 BC (which it was doing even in code paths that had nothing to do with to_timestamp). I also did some minor code beautification in the non-ISO-day-number code path. This area has been busted all along, but because the code has been rewritten repeatedly, it would be considerable trouble to back-patch. It's such a corner case that it doesn't seem worth the effort.
* Update copyright for 2009.Bruce Momjian2009-01-01
|
* Add support for input and output of interval values formatted per ISO 8601;Tom Lane2008-11-11
| | | | | | | | specifically, we can input either the "format with designators" or the "alternative format", and we can output the former when IntervalStyle is set to iso_8601. Ron Mayer
* Add a new GUC variable called "IntervalStyle" that decouples interval outputTom Lane2008-11-09
| | | | | | | | | | from DateStyle, and create a new interval style that produces output matching the SQL standard (at least for interval values that fall within the standard's restrictions). IntervalStyle is also used to resolve the conflict between the standard and traditional Postgres rules for interpreting negative interval input. Ron Mayer
* Fix EncodeSpecialTimestamp to throw error on unrecognized input, rather thanTom Lane2008-10-14
| | | | returning a failure code that none of its callers bothered to check for.
* Adjust the parser to accept the typename syntax INTERVAL ... SECOND(n)Tom Lane2008-09-11
| | | | | | | | | | | | | | | | | | | 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.)
* Make our parsing of INTERVAL literals spec-compliant (or at least a heck ofTom Lane2008-09-10
| | | | | | | | | | | | | | | 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.
* Fix AT TIME ZONE (in all three variants) so that we first try to interpretTom Lane2008-07-07
| | | | | | | | | | | | | | | | the timezone argument as a timezone abbreviation, and only try it as a full timezone name if that fails. The zic database has four zones (CET, EET, MET, WET) that are full daylight-savings zones and yet have names that are the same as their abbreviations for standard time, resulting in ambiguity. In the timestamp input functions we resolve the ambiguity by preferring the abbreviation, and AT TIME ZONE should work the same way. (No functionality is lost because the zic database also has other names for these zones, eg Europe/Zurich.) Per gripe from Jaromir Talir. Backpatch to 8.1. Older releases did not have the issue because AT TIME ZONE only accepted abbreviations not zone names. (Thus, this patch also arguably fixes a compatibility botch introduced at 8.1: in ambiguous cases we now behave the same as 8.0 did.)
* Add timestamp and timestamptz versions of generate_series().Tom Lane2008-05-04
| | | | Hitoshi Harada
* Add pg_conf_load_time() function to report when the Postgres configurationTom Lane2008-05-04
| | | | | | files were last loaded. George Gensure
* Simplify and standardize conversions between TEXT datums and ordinary CTom Lane2008-03-25
| | | | | | | | | | | | | | | | | | | | strings. This patch introduces four support functions cstring_to_text, cstring_to_text_with_len, text_to_cstring, and text_to_cstring_buffer, and two macros CStringGetTextDatum and TextDatumGetCString. A number of existing macros that provided variants on these themes were removed. Most of the places that need to make such conversions now require just one function or macro call, in place of the multiple notational layers that used to be needed. There are no longer any direct calls of textout or textin, and we got most of the places that were using handmade conversions via memcpy (there may be a few still lurking, though). This commit doesn't make any serious effort to eliminate transient memory leaks caused by detoasting toasted text objects before they reach text_to_cstring. We changed PG_GETARG_TEXT_P to PG_GETARG_TEXT_PP in a few places where it was easy, but much more could be done. Brendan Jurd and Tom Lane
* Get rid of a bunch of #ifdef HAVE_INT64_TIMESTAMP conditionals by inventingTom Lane2008-03-21
| | | | | | | | | | a new typedef TimeOffset to represent an intermediate time value. It's either int64 or double as appropriate, and in most usages will be measured in microseconds or seconds the same as Timestamp. We don't call it Timestamp, though, since the value doesn't necessarily represent an absolute time instant. Warren Turkal
* Replace time_t with pg_time_t (same values, but always int64) in on-diskTom Lane2008-02-17
| | | | | | | | | | | | | | data structures and backend internal APIs. This solves problems we've seen recently with inconsistent layout of pg_control between machines that have 32-bit time_t and those that have already migrated to 64-bit time_t. Also, we can get out from under the problem that Windows' Unix-API emulation is not consistent about the width of time_t. There are a few remaining places where local time_t variables are used to hold the current or recent result of time(NULL). I didn't bother changing these since they do not affect any cross-module APIs and surely all platforms will have 64-bit time_t before overflow becomes an actual risk. time_t should be avoided for anything visible to extension modules, however.
* Update copyrights in source tree to 2008.Bruce Momjian2008-01-01
|
* pgindent run for 8.3.Bruce Momjian2007-11-15
|
* Fix overflow in extract(epoch from interval) for intervals exceeding 68 years.Tom Lane2007-09-16
| | | | | Seems to have been introduced in 8.1 by careless SECS_PER_DAY search-and-replace.
* Switch over to using the src/timezone functions for formatting timestampsTom Lane2007-08-04
| | | | | | | | | | | | | | displayed in the postmaster log. This avoids Windows-specific problems with localized time zone names that are in the wrong encoding, and generally seems like a good idea to forestall other potential platform-dependent issues. To preserve the existing behavior that all backends will log in the same time zone, create a new GUC variable log_timezone that can only be changed on a system-wide basis, and reference log-related calculations to that zone instead of the TimeZone variable. This fixes the issue reported by Hiroshi Saito that timestamps printed by xlog.c startup could be improperly localized on Windows. We still need a simpler patch for that problem in the back branches, however.
* Properly adjust age() seconds to match the sign of the larger units.Bruce Momjian2007-07-18
| | | | Patch from Tom.
* Fix up hash functions for datetime datatypes so that they don't takeTom Lane2007-07-06
| | | | | | unwarranted liberties with int8 vs float8 values for these types. Specifically, be sure to apply either hashint8 or hashfloat8 depending on HAVE_INT64_TIMESTAMP. Per my gripe of even date.
* Tweak the API for per-datatype typmodin functions so that they are passedTom Lane2007-06-15
| | | | | | | | | | | | an array of strings rather than an array of integers, and allow any simple constant or identifier to be used in typmods; for example create table foo (f1 widget(42,'23skidoo',point)); Of course the typmodin function has still got to pack this info into a non-negative int32 for storage, but it's still a useful improvement in flexibility, especially considering that you can do nearly anything if you are willing to keep the info in a side table. We can get away with this change since we have not yet released a version providing user-definable typmods. Per discussion.
* Downgrade implicit casts to text to be assignment-only, except for the onesTom Lane2007-06-05
| | | | | | | | | | | | | | | | | | | | | | | | | from the other string-category types; this eliminates a lot of surprising interpretations that the parser could formerly make when there was no directly applicable operator. Create a general mechanism that supports casts to and from the standard string types (text,varchar,bpchar) for *every* datatype, by invoking the datatype's I/O functions. These new casts are assignment-only in the to-string direction, explicit-only in the other, and therefore should create no surprising behavior. Remove a bunch of thereby-obsoleted datatype-specific casting functions. The "general mechanism" is a new expression node type CoerceViaIO that can actually convert between *any* two datatypes if their external text representations are compatible. This is more general than needed for the immediate feature, but might be useful in plpgsql or other places in future. This commit does nothing about the issue that applying the concatenation operator || to non-text types will now fail, often with strange error messages due to misinterpreting the operator as array concatenation. Since it often (not always) worked before, we should either make it succeed or at least give a more user-friendly error; but details are still under debate. Peter Eisentraut and Tom Lane
* Change the timestamps recorded in transaction commit/abort xlog recordsTom Lane2007-04-30
| | | | | | | | | from time_t to TimestampTz representation. This provides full gettimeofday() resolution of the timestamps, which might be useful when attempting to do point-in-time recovery --- previously it was not possible to specify the stop point with sub-second resolution. But mostly this is to get rid of TimestampTz-to-time_t conversion overhead during commit. Per my proposal of a day or two back.
* Implement rate-limiting logic on how often backends will attempt to sendTom Lane2007-04-30
| | | | | | | | | | | | | | messages to the stats collector. This avoids the problem that enabling stats_row_level for autovacuum has a significant overhead for short read-only transactions, as noted by Arjen van der Meijden. We can avoid an extra gettimeofday call by piggybacking on the one done for WAL-logging xact commit or abort (although that doesn't help read-only transactions, since they don't WAL-log anything). In my proposal for this, I noted that we could change the WAL log entries for commit/abort to record full TimestampTz precision, instead of only time_t as at present. That's not done in this patch, but will be committed separately.
* Replace direct assignments to VARATT_SIZEP(x) with SET_VARSIZE(x, len).Tom Lane2007-02-27
| | | | | | | | | | | Get rid of VARATT_SIZE and VARATT_DATA, which were simply redundant with VARSIZE and VARDATA, and as a consequence almost no code was using the longer names. Rename the length fields of struct varlena and various derived structures to catch anyplace that was accessing them directly; and clean up various places so caught. In itself this patch doesn't change any behavior at all, but it is necessary infrastructure if we hope to play any games with the representation of varlena headers. Greg Stark and Tom Lane
* Add "isodow" option to EXTRACT() and date_part() where Sunday = 7.Bruce Momjian2007-02-19
|
* Add two new format fields for use with to_char(), to_date() andBruce Momjian2007-02-16
| | | | | | | | | | | | | | to_timestamp(): - ID for day-of-week - IDDD for day-of-year This makes it possible to convert ISO week dates to and from text fully represented in either week ('IYYY-IW-ID') or day-of-year ('IYYY-IDDD') format. I have also added an 'isoyear' field for use with extract / date_part. Brendan Jurd
* Update CVS HEAD for 2007 copyright. Back branches are typically notBruce Momjian2007-01-05
| | | | back-stamped for this.
* Support type modifiers for user-defined types, and pull most knowledgeTom Lane2006-12-30
| | | | | | about typmod representation for standard types out into type-specific typmod I/O functions. Teodor Sigaev, with some editorialization by Tom Lane.
* Suppress a few 'uninitialized variable' warnings that gcc emits only atTom Lane2006-11-11
| | | | | -O3 or higher (presumably because it inlines more things). Per gripe from Mark Mielke.
* pgindent run for 8.2.Bruce Momjian2006-10-04
|
* Fix imprecision from interval rounding of multiplication/division.Bruce Momjian2006-09-05
| | | | Bruce, Michael Glaesemann
* Properly round months into days and into seconds for intervalBruce Momjian2006-09-03
| | | | | | | multiplication/division queries like select '41 mon 10:00:00'::interval / 10 as "pos". Report from Michael Glaesemann
* Allow include files to compile own their own.Bruce Momjian2006-07-13
| | | | | | | Strip unused include files out unused include files, and add needed includes to C files. The next step is to remove unused include files in C files.
* Remove redundant gettimeofday() calls to the extent practical withoutTom Lane2006-06-20
| | | | | | | | | | | changing semantics too much. statement_timestamp is now set immediately upon receipt of a client command message, and the various places that used to do their own gettimeofday() calls to mark command startup are referenced to that instead. I have also made stats_command_string use that same value for pg_stat_activity.query_start for both the command itself and its eventual replacement by <IDLE> or <idle in transaction>. There was some debate about that, but no argument that seemed convincing enough to justify an extra gettimeofday() call.
* Add statement_timestamp(), clock_timestamp(), andBruce Momjian2006-04-25
| | | | | | | | | transaction_timestamp() (just like now()). Also update statement_timeout() to mention it is statement arrival time that is measured. Catalog version updated.
* Attached is the new patch. To summarize:Bruce Momjian2006-03-06
| | | | | | | | | | | | | | | | | | | | | | | | | | - new function justify_interval(interval) - modified function justify_hours(interval) - modified function justify_days(interval) These functions are defined to meet the requirements as discussed in this thread. Specifically: - justify_hours makes certain the sign bit on the hours matches the sign bit on the days. It only checks the sign bit on the days, and not the months, when determining if the hours should be positive or negative. After the call, -24 < hours < 24. - justify_days makes certain the sign bit on the days matches the sign bit on the months. It's behavior does not depend on the hours, nor does it modify the hours. After the call, -30 < days < 30. - justify_interval makes sure the sign bits on all three fields months, days, and hours are all the same. After the call, -24 < hours < 24 AND -30 < days < 30. Mark Dilger
* Update copyright for 2006. Update scripts.Bruce Momjian2006-03-05
|
* Fix up comment munged by pg_indent. (Not pg_indent's fault; should haveTom Lane2005-11-22
| | | | protected comment with dashes the first time round.)