Skip to content

Commit 0de45c1

Browse files
committed
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.
1 parent f938c2b commit 0de45c1

File tree

9 files changed

+355
-18
lines changed

9 files changed

+355
-18
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 183 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.101 2004/03/15 03:29:22 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.102 2004/03/22 01:38:17 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -48,6 +48,7 @@ static int EncodeSpecialTimestamp(Timestamp dt, char *str);
4848
static Timestamp dt2local(Timestamp dt, int timezone);
4949
static void AdjustTimestampForTypmod(Timestamp *time, int32 typmod);
5050
static void AdjustIntervalForTypmod(Interval *interval, int32 typmod);
51+
static TimestampTz timestamp2timestamptz(Timestamp timestamp);
5152

5253

5354
/*****************************************************************************
@@ -1393,6 +1394,179 @@ timestamp_cmp(PG_FUNCTION_ARGS)
13931394
}
13941395

13951396

1397+
/*
1398+
* Crosstype comparison functions for timestamp vs timestamptz
1399+
*/
1400+
1401+
Datum
1402+
timestamp_eq_timestamptz(PG_FUNCTION_ARGS)
1403+
{
1404+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(0);
1405+
TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1);
1406+
TimestampTz dt1;
1407+
1408+
dt1 = timestamp2timestamptz(timestampVal);
1409+
1410+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
1411+
}
1412+
1413+
Datum
1414+
timestamp_ne_timestamptz(PG_FUNCTION_ARGS)
1415+
{
1416+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(0);
1417+
TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1);
1418+
TimestampTz dt1;
1419+
1420+
dt1 = timestamp2timestamptz(timestampVal);
1421+
1422+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
1423+
}
1424+
1425+
Datum
1426+
timestamp_lt_timestamptz(PG_FUNCTION_ARGS)
1427+
{
1428+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(0);
1429+
TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1);
1430+
TimestampTz dt1;
1431+
1432+
dt1 = timestamp2timestamptz(timestampVal);
1433+
1434+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
1435+
}
1436+
1437+
Datum
1438+
timestamp_gt_timestamptz(PG_FUNCTION_ARGS)
1439+
{
1440+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(0);
1441+
TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1);
1442+
TimestampTz dt1;
1443+
1444+
dt1 = timestamp2timestamptz(timestampVal);
1445+
1446+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
1447+
}
1448+
1449+
Datum
1450+
timestamp_le_timestamptz(PG_FUNCTION_ARGS)
1451+
{
1452+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(0);
1453+
TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1);
1454+
TimestampTz dt1;
1455+
1456+
dt1 = timestamp2timestamptz(timestampVal);
1457+
1458+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
1459+
}
1460+
1461+
Datum
1462+
timestamp_ge_timestamptz(PG_FUNCTION_ARGS)
1463+
{
1464+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(0);
1465+
TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1);
1466+
TimestampTz dt1;
1467+
1468+
dt1 = timestamp2timestamptz(timestampVal);
1469+
1470+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
1471+
}
1472+
1473+
Datum
1474+
timestamp_cmp_timestamptz(PG_FUNCTION_ARGS)
1475+
{
1476+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(0);
1477+
TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1);
1478+
TimestampTz dt1;
1479+
1480+
dt1 = timestamp2timestamptz(timestampVal);
1481+
1482+
PG_RETURN_INT32(timestamp_cmp_internal(dt1, dt2));
1483+
}
1484+
1485+
Datum
1486+
timestamptz_eq_timestamp(PG_FUNCTION_ARGS)
1487+
{
1488+
TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0);
1489+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(1);
1490+
TimestampTz dt2;
1491+
1492+
dt2 = timestamp2timestamptz(timestampVal);
1493+
1494+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
1495+
}
1496+
1497+
Datum
1498+
timestamptz_ne_timestamp(PG_FUNCTION_ARGS)
1499+
{
1500+
TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0);
1501+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(1);
1502+
TimestampTz dt2;
1503+
1504+
dt2 = timestamp2timestamptz(timestampVal);
1505+
1506+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
1507+
}
1508+
1509+
Datum
1510+
timestamptz_lt_timestamp(PG_FUNCTION_ARGS)
1511+
{
1512+
TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0);
1513+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(1);
1514+
TimestampTz dt2;
1515+
1516+
dt2 = timestamp2timestamptz(timestampVal);
1517+
1518+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
1519+
}
1520+
1521+
Datum
1522+
timestamptz_gt_timestamp(PG_FUNCTION_ARGS)
1523+
{
1524+
TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0);
1525+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(1);
1526+
TimestampTz dt2;
1527+
1528+
dt2 = timestamp2timestamptz(timestampVal);
1529+
1530+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
1531+
}
1532+
1533+
Datum
1534+
timestamptz_le_timestamp(PG_FUNCTION_ARGS)
1535+
{
1536+
TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0);
1537+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(1);
1538+
TimestampTz dt2;
1539+
1540+
dt2 = timestamp2timestamptz(timestampVal);
1541+
1542+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
1543+
}
1544+
1545+
Datum
1546+
timestamptz_ge_timestamp(PG_FUNCTION_ARGS)
1547+
{
1548+
TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0);
1549+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(1);
1550+
TimestampTz dt2;
1551+
1552+
dt2 = timestamp2timestamptz(timestampVal);
1553+
1554+
PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
1555+
}
1556+
1557+
Datum
1558+
timestamptz_cmp_timestamp(PG_FUNCTION_ARGS)
1559+
{
1560+
TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0);
1561+
Timestamp timestampVal = PG_GETARG_TIMESTAMP(1);
1562+
TimestampTz dt2;
1563+
1564+
dt2 = timestamp2timestamptz(timestampVal);
1565+
1566+
PG_RETURN_INT32(timestamp_cmp_internal(dt1, dt2));
1567+
}
1568+
1569+
13961570
/*
13971571
* interval_relop - is interval1 relop interval2
13981572
*
@@ -3635,6 +3809,13 @@ Datum
36353809
timestamp_timestamptz(PG_FUNCTION_ARGS)
36363810
{
36373811
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
3812+
3813+
PG_RETURN_TIMESTAMPTZ(timestamp2timestamptz(timestamp));
3814+
}
3815+
3816+
static TimestampTz
3817+
timestamp2timestamptz(Timestamp timestamp)
3818+
{
36383819
TimestampTz result;
36393820
struct tm tt,
36403821
*tm = &tt;
@@ -3658,7 +3839,7 @@ timestamp_timestamptz(PG_FUNCTION_ARGS)
36583839
errmsg("timestamp out of range")));
36593840
}
36603841

3661-
PG_RETURN_TIMESTAMPTZ(result);
3842+
return result;
36623843
}
36633844

36643845
/* timestamptz_timestamp()

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.221 2004/03/17 20:48:42 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.222 2004/03/22 01:38:17 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200403171
56+
#define CATALOG_VERSION_NO 200403211
5757

5858
#endif

src/include/catalog/pg_amop.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
26-
* $PostgreSQL: pgsql/src/include/catalog/pg_amop.h,v 1.58 2004/02/14 20:16:17 tgl Exp $
26+
* $PostgreSQL: pgsql/src/include/catalog/pg_amop.h,v 1.59 2004/03/22 01:38:17 tgl Exp $
2727
*
2828
* NOTES
2929
* the genbki.sh script reads this file and generates .bki
@@ -349,6 +349,12 @@ DATA(insert ( 2039 1082 2 f 2372 ));
349349
DATA(insert ( 2039 1082 3 f 2373 ));
350350
DATA(insert ( 2039 1082 4 f 2374 ));
351351
DATA(insert ( 2039 1082 5 f 2375 ));
352+
/* crosstype operators vs timestamptz */
353+
DATA(insert ( 2039 1184 1 f 2534 ));
354+
DATA(insert ( 2039 1184 2 f 2535 ));
355+
DATA(insert ( 2039 1184 3 f 2536 ));
356+
DATA(insert ( 2039 1184 4 f 2537 ));
357+
DATA(insert ( 2039 1184 5 f 2538 ));
352358

353359
/*
354360
* btree timestamptz_ops
@@ -365,6 +371,12 @@ DATA(insert ( 1998 1082 2 f 2385 ));
365371
DATA(insert ( 1998 1082 3 f 2386 ));
366372
DATA(insert ( 1998 1082 4 f 2387 ));
367373
DATA(insert ( 1998 1082 5 f 2388 ));
374+
/* crosstype operators vs timestamp */
375+
DATA(insert ( 1998 1114 1 f 2540 ));
376+
DATA(insert ( 1998 1114 2 f 2541 ));
377+
DATA(insert ( 1998 1114 3 f 2542 ));
378+
DATA(insert ( 1998 1114 4 f 2543 ));
379+
DATA(insert ( 1998 1114 5 f 2544 ));
368380

369381
/*
370382
* btree interval_ops

src/include/catalog/pg_amproc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
22-
* $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.47 2004/02/14 20:16:17 tgl Exp $
22+
* $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.48 2004/03/22 01:38:17 tgl Exp $
2323
*
2424
* NOTES
2525
* the genbki.sh script reads this file and generates .bki
@@ -117,11 +117,13 @@ DATA(insert ( 1994 0 1 360 ));
117117
DATA(insert ( 1996 0 1 1107 ));
118118
DATA(insert ( 1998 0 1 1314 ));
119119
DATA(insert ( 1998 1082 1 2383 ));
120+
DATA(insert ( 1998 1114 1 2533 ));
120121
DATA(insert ( 2000 0 1 1358 ));
121122
DATA(insert ( 2002 0 1 1672 ));
122123
DATA(insert ( 2003 0 1 360 ));
123124
DATA(insert ( 2039 0 1 2045 ));
124125
DATA(insert ( 2039 1082 1 2370 ));
126+
DATA(insert ( 2039 1184 1 2526 ));
125127
DATA(insert ( 2095 0 1 2166 ));
126128
DATA(insert ( 2096 0 1 2166 ));
127129
DATA(insert ( 2097 0 1 2180 ));

src/include/catalog/pg_operator.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.124 2004/02/14 20:16:17 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.125 2004/03/22 01:38:17 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -822,32 +822,48 @@ DATA(insert OID = 2337 ( "~<>~" PGNSP PGUID b f 19 19 16 2337 2334 0 0 0 0 name_
822822

823823
DATA(insert OID = 2345 ( "<" PGNSP PGUID b f 1082 1114 16 2375 2348 0 0 0 0 date_lt_timestamp scalarltsel scalarltjoinsel ));
824824
DATA(insert OID = 2346 ( "<=" PGNSP PGUID b f 1082 1114 16 2374 2349 0 0 0 0 date_le_timestamp scalarltsel scalarltjoinsel ));
825-
DATA(insert OID = 2347 ( "=" PGNSP PGUID b f 1082 1114 16 2373 2350 0 0 0 0 date_eq_timestamp eqsel eqjoinsel ));
825+
DATA(insert OID = 2347 ( "=" PGNSP PGUID b f 1082 1114 16 2373 2350 1095 2062 2345 2349 date_eq_timestamp eqsel eqjoinsel ));
826826
DATA(insert OID = 2348 ( ">=" PGNSP PGUID b f 1082 1114 16 2372 2345 0 0 0 0 date_ge_timestamp scalargtsel scalargtjoinsel ));
827827
DATA(insert OID = 2349 ( ">" PGNSP PGUID b f 1082 1114 16 2371 2346 0 0 0 0 date_gt_timestamp scalargtsel scalargtjoinsel ));
828828
DATA(insert OID = 2350 ( "<>" PGNSP PGUID b f 1082 1114 16 2376 2347 0 0 0 0 date_ne_timestamp neqsel neqjoinsel ));
829829

830830
DATA(insert OID = 2358 ( "<" PGNSP PGUID b f 1082 1184 16 2388 2361 0 0 0 0 date_lt_timestamptz scalarltsel scalarltjoinsel ));
831831
DATA(insert OID = 2359 ( "<=" PGNSP PGUID b f 1082 1184 16 2387 2362 0 0 0 0 date_le_timestamptz scalarltsel scalarltjoinsel ));
832-
DATA(insert OID = 2360 ( "=" PGNSP PGUID b f 1082 1184 16 2386 2363 0 0 0 0 date_eq_timestamptz eqsel eqjoinsel ));
832+
DATA(insert OID = 2360 ( "=" PGNSP PGUID b f 1082 1184 16 2386 2363 1095 1322 2358 2362 date_eq_timestamptz eqsel eqjoinsel ));
833833
DATA(insert OID = 2361 ( ">=" PGNSP PGUID b f 1082 1184 16 2385 2358 0 0 0 0 date_ge_timestamptz scalargtsel scalargtjoinsel ));
834834
DATA(insert OID = 2362 ( ">" PGNSP PGUID b f 1082 1184 16 2384 2359 0 0 0 0 date_gt_timestamptz scalargtsel scalargtjoinsel ));
835835
DATA(insert OID = 2363 ( "<>" PGNSP PGUID b f 1082 1184 16 2389 2360 0 0 0 0 date_ne_timestamptz neqsel neqjoinsel ));
836836

837837
DATA(insert OID = 2371 ( "<" PGNSP PGUID b f 1114 1082 16 2349 2374 0 0 0 0 timestamp_lt_date scalarltsel scalarltjoinsel ));
838838
DATA(insert OID = 2372 ( "<=" PGNSP PGUID b f 1114 1082 16 2348 2375 0 0 0 0 timestamp_le_date scalarltsel scalarltjoinsel ));
839-
DATA(insert OID = 2373 ( "=" PGNSP PGUID b f 1114 1082 16 2347 2376 0 0 0 0 timestamp_eq_date eqsel eqjoinsel ));
839+
DATA(insert OID = 2373 ( "=" PGNSP PGUID b f 1114 1082 16 2347 2376 2062 1095 2371 2375 timestamp_eq_date eqsel eqjoinsel ));
840840
DATA(insert OID = 2374 ( ">=" PGNSP PGUID b f 1114 1082 16 2346 2371 0 0 0 0 timestamp_ge_date scalargtsel scalargtjoinsel ));
841841
DATA(insert OID = 2375 ( ">" PGNSP PGUID b f 1114 1082 16 2345 2372 0 0 0 0 timestamp_gt_date scalargtsel scalargtjoinsel ));
842842
DATA(insert OID = 2376 ( "<>" PGNSP PGUID b f 1114 1082 16 2350 2373 0 0 0 0 timestamp_ne_date neqsel neqjoinsel ));
843843

844844
DATA(insert OID = 2384 ( "<" PGNSP PGUID b f 1184 1082 16 2362 2387 0 0 0 0 timestamptz_lt_date scalarltsel scalarltjoinsel ));
845845
DATA(insert OID = 2385 ( "<=" PGNSP PGUID b f 1184 1082 16 2361 2388 0 0 0 0 timestamptz_le_date scalarltsel scalarltjoinsel ));
846-
DATA(insert OID = 2386 ( "=" PGNSP PGUID b f 1184 1082 16 2360 2389 0 0 0 0 timestamptz_eq_date eqsel eqjoinsel ));
846+
DATA(insert OID = 2386 ( "=" PGNSP PGUID b f 1184 1082 16 2360 2389 1322 1095 2384 2388 timestamptz_eq_date eqsel eqjoinsel ));
847847
DATA(insert OID = 2387 ( ">=" PGNSP PGUID b f 1184 1082 16 2359 2384 0 0 0 0 timestamptz_ge_date scalargtsel scalargtjoinsel ));
848848
DATA(insert OID = 2388 ( ">" PGNSP PGUID b f 1184 1082 16 2358 2385 0 0 0 0 timestamptz_gt_date scalargtsel scalargtjoinsel ));
849849
DATA(insert OID = 2389 ( "<>" PGNSP PGUID b f 1184 1082 16 2363 2386 0 0 0 0 timestamptz_ne_date neqsel neqjoinsel ));
850850

851+
/* crosstype operations for timestamp vs. timestamptz */
852+
853+
DATA(insert OID = 2534 ( "<" PGNSP PGUID b f 1114 1184 16 2544 2537 0 0 0 0 timestamp_lt_timestamptz scalarltsel scalarltjoinsel ));
854+
DATA(insert OID = 2535 ( "<=" PGNSP PGUID b f 1114 1184 16 2543 2538 0 0 0 0 timestamp_le_timestamptz scalarltsel scalarltjoinsel ));
855+
DATA(insert OID = 2536 ( "=" PGNSP PGUID b f 1114 1184 16 2542 2539 2062 1322 2534 2538 timestamp_eq_timestamptz eqsel eqjoinsel ));
856+
DATA(insert OID = 2537 ( ">=" PGNSP PGUID b f 1114 1184 16 2541 2534 0 0 0 0 timestamp_ge_timestamptz scalargtsel scalargtjoinsel ));
857+
DATA(insert OID = 2538 ( ">" PGNSP PGUID b f 1114 1184 16 2540 2535 0 0 0 0 timestamp_gt_timestamptz scalargtsel scalargtjoinsel ));
858+
DATA(insert OID = 2539 ( "<>" PGNSP PGUID b f 1114 1184 16 2545 2536 0 0 0 0 timestamp_ne_timestamptz neqsel neqjoinsel ));
859+
860+
DATA(insert OID = 2540 ( "<" PGNSP PGUID b f 1184 1114 16 2538 2543 0 0 0 0 timestamptz_lt_timestamp scalarltsel scalarltjoinsel ));
861+
DATA(insert OID = 2541 ( "<=" PGNSP PGUID b f 1184 1114 16 2537 2544 0 0 0 0 timestamptz_le_timestamp scalarltsel scalarltjoinsel ));
862+
DATA(insert OID = 2542 ( "=" PGNSP PGUID b f 1184 1114 16 2536 2545 1322 2062 2540 2544 timestamptz_eq_timestamp eqsel eqjoinsel ));
863+
DATA(insert OID = 2543 ( ">=" PGNSP PGUID b f 1184 1114 16 2535 2540 0 0 0 0 timestamptz_ge_timestamp scalargtsel scalargtjoinsel ));
864+
DATA(insert OID = 2544 ( ">" PGNSP PGUID b f 1184 1114 16 2534 2541 0 0 0 0 timestamptz_gt_timestamp scalargtsel scalargtjoinsel ));
865+
DATA(insert OID = 2545 ( "<>" PGNSP PGUID b f 1184 1114 16 2539 2542 0 0 0 0 timestamptz_ne_timestamp neqsel neqjoinsel ));
866+
851867

852868
/*
853869
* function prototypes

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy