diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-04-30 21:01:53 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-04-30 21:01:53 +0000 |
commit | c4320619635800a6116a02eee08b232c5abea266 (patch) | |
tree | 3db9b7562baf005c9ccf4976c293a4328dfa9509 /src/backend/utils/adt/timestamp.c | |
parent | 641912b4d17fd214a5e5bae4e7bb9ddbc28b144b (diff) | |
download | postgresql-c4320619635800a6116a02eee08b232c5abea266.tar.gz postgresql-c4320619635800a6116a02eee08b232c5abea266.zip |
Change the timestamps recorded in transaction commit/abort xlog records
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.
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 2a83ae96b2a..f9fb9ef5820 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.175 2007/04/30 03:23:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.176 2007/04/30 21:01:52 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1301,6 +1301,33 @@ timestamptz_to_time_t(TimestampTz t) return result; } +/* + * Produce a C-string representation of a TimestampTz. + * + * This is mostly for use in emitting messages. The primary difference + * from timestamptz_out is that we force the output format to ISO. Note + * also that the result is in a static buffer, not pstrdup'd. + */ +const char * +timestamptz_to_str(TimestampTz t) +{ + static char buf[MAXDATELEN + 1]; + int tz; + struct pg_tm tt, + *tm = &tt; + fsec_t fsec; + char *tzn; + + if (TIMESTAMP_NOT_FINITE(t)) + EncodeSpecialTimestamp(t, buf); + else if (timestamp2tm(t, &tz, tm, &fsec, &tzn, NULL) == 0) + EncodeDateTime(tm, fsec, &tz, &tzn, USE_ISO_DATES, buf); + else + strlcpy(buf, "(timestamp out of range)", sizeof(buf)); + + return buf; +} + void dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec) |