diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-03-22 01:38:18 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-03-22 01:38:18 +0000 |
commit | 0de45c1c2753763c5ca7d4904075e2cae80bb353 (patch) | |
tree | 9d4b34360c540365318a2e0c49dc1f9891b41464 /src/backend/utils/adt/timestamp.c | |
parent | f938c2b91bebb7f436a3615cf86347d7261f71e8 (diff) | |
download | postgresql-0de45c1c2753763c5ca7d4904075e2cae80bb353.tar.gz postgresql-0de45c1c2753763c5ca7d4904075e2cae80bb353.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 185 |
1 files changed, 183 insertions, 2 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 582bc369d5d..11a75cc2bd5 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.101 2004/03/15 03:29:22 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.102 2004/03/22 01:38:17 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -48,6 +48,7 @@ static int EncodeSpecialTimestamp(Timestamp dt, char *str); static Timestamp dt2local(Timestamp dt, int timezone); static void AdjustTimestampForTypmod(Timestamp *time, int32 typmod); static void AdjustIntervalForTypmod(Interval *interval, int32 typmod); +static TimestampTz timestamp2timestamptz(Timestamp timestamp); /***************************************************************************** @@ -1394,6 +1395,179 @@ timestamp_cmp(PG_FUNCTION_ARGS) /* + * Crosstype comparison functions for timestamp vs timestamptz + */ + +Datum +timestamp_eq_timestamptz(PG_FUNCTION_ARGS) +{ + Timestamp timestampVal = PG_GETARG_TIMESTAMP(0); + TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); + TimestampTz dt1; + + dt1 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0); +} + +Datum +timestamp_ne_timestamptz(PG_FUNCTION_ARGS) +{ + Timestamp timestampVal = PG_GETARG_TIMESTAMP(0); + TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); + TimestampTz dt1; + + dt1 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0); +} + +Datum +timestamp_lt_timestamptz(PG_FUNCTION_ARGS) +{ + Timestamp timestampVal = PG_GETARG_TIMESTAMP(0); + TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); + TimestampTz dt1; + + dt1 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0); +} + +Datum +timestamp_gt_timestamptz(PG_FUNCTION_ARGS) +{ + Timestamp timestampVal = PG_GETARG_TIMESTAMP(0); + TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); + TimestampTz dt1; + + dt1 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0); +} + +Datum +timestamp_le_timestamptz(PG_FUNCTION_ARGS) +{ + Timestamp timestampVal = PG_GETARG_TIMESTAMP(0); + TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); + TimestampTz dt1; + + dt1 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0); +} + +Datum +timestamp_ge_timestamptz(PG_FUNCTION_ARGS) +{ + Timestamp timestampVal = PG_GETARG_TIMESTAMP(0); + TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); + TimestampTz dt1; + + dt1 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0); +} + +Datum +timestamp_cmp_timestamptz(PG_FUNCTION_ARGS) +{ + Timestamp timestampVal = PG_GETARG_TIMESTAMP(0); + TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); + TimestampTz dt1; + + dt1 = timestamp2timestamptz(timestampVal); + + PG_RETURN_INT32(timestamp_cmp_internal(dt1, dt2)); +} + +Datum +timestamptz_eq_timestamp(PG_FUNCTION_ARGS) +{ + TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); + Timestamp timestampVal = PG_GETARG_TIMESTAMP(1); + TimestampTz dt2; + + dt2 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0); +} + +Datum +timestamptz_ne_timestamp(PG_FUNCTION_ARGS) +{ + TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); + Timestamp timestampVal = PG_GETARG_TIMESTAMP(1); + TimestampTz dt2; + + dt2 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0); +} + +Datum +timestamptz_lt_timestamp(PG_FUNCTION_ARGS) +{ + TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); + Timestamp timestampVal = PG_GETARG_TIMESTAMP(1); + TimestampTz dt2; + + dt2 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0); +} + +Datum +timestamptz_gt_timestamp(PG_FUNCTION_ARGS) +{ + TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); + Timestamp timestampVal = PG_GETARG_TIMESTAMP(1); + TimestampTz dt2; + + dt2 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0); +} + +Datum +timestamptz_le_timestamp(PG_FUNCTION_ARGS) +{ + TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); + Timestamp timestampVal = PG_GETARG_TIMESTAMP(1); + TimestampTz dt2; + + dt2 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0); +} + +Datum +timestamptz_ge_timestamp(PG_FUNCTION_ARGS) +{ + TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); + Timestamp timestampVal = PG_GETARG_TIMESTAMP(1); + TimestampTz dt2; + + dt2 = timestamp2timestamptz(timestampVal); + + PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0); +} + +Datum +timestamptz_cmp_timestamp(PG_FUNCTION_ARGS) +{ + TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); + Timestamp timestampVal = PG_GETARG_TIMESTAMP(1); + TimestampTz dt2; + + dt2 = timestamp2timestamptz(timestampVal); + + PG_RETURN_INT32(timestamp_cmp_internal(dt1, dt2)); +} + + +/* * interval_relop - is interval1 relop interval2 * * collate invalid interval at the end @@ -3635,6 +3809,13 @@ Datum timestamp_timestamptz(PG_FUNCTION_ARGS) { Timestamp timestamp = PG_GETARG_TIMESTAMP(0); + + PG_RETURN_TIMESTAMPTZ(timestamp2timestamptz(timestamp)); +} + +static TimestampTz +timestamp2timestamptz(Timestamp timestamp) +{ TimestampTz result; struct tm tt, *tm = &tt; @@ -3658,7 +3839,7 @@ timestamp_timestamptz(PG_FUNCTION_ARGS) errmsg("timestamp out of range"))); } - PG_RETURN_TIMESTAMPTZ(result); + return result; } /* timestamptz_timestamp() |