1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-22 14:32:25 +03:00

Add more cross-type comparisons to contrib/btree_gin.

Using the just-added infrastructure, extend btree_gin to support
cross-type operators in its other opclasses.  All of the cross-type
comparison operators supported by the core btree opclasses for
these datatypes are now available for btree_gin indexes as well.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
Discussion: https://postgr.es/m/262624.1738460652@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2025-07-03 16:30:38 -04:00
parent e2b64fcef3
commit fc896821c4
16 changed files with 1725 additions and 37 deletions

View File

@@ -49,3 +49,365 @@ SELECT * FROM test_date WHERE i>'2004-10-26'::date ORDER BY i;
10-28-2004
(2 rows)
explain (costs off)
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamp ORDER BY i;
QUERY PLAN
-----------------------------------------------------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_date
Recheck Cond: (i < 'Tue Oct 26 00:00:00 2004'::timestamp without time zone)
-> Bitmap Index Scan on idx_date
Index Cond: (i < 'Tue Oct 26 00:00:00 2004'::timestamp without time zone)
(6 rows)
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamp ORDER BY i;
i
------------
10-23-2004
10-24-2004
10-25-2004
(3 rows)
SELECT * FROM test_date WHERE i<='2004-10-26'::timestamp ORDER BY i;
i
------------
10-23-2004
10-24-2004
10-25-2004
10-26-2004
(4 rows)
SELECT * FROM test_date WHERE i='2004-10-26'::timestamp ORDER BY i;
i
------------
10-26-2004
(1 row)
SELECT * FROM test_date WHERE i>='2004-10-26'::timestamp ORDER BY i;
i
------------
10-26-2004
10-27-2004
10-28-2004
(3 rows)
SELECT * FROM test_date WHERE i>'2004-10-26'::timestamp ORDER BY i;
i
------------
10-27-2004
10-28-2004
(2 rows)
explain (costs off)
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamptz ORDER BY i;
QUERY PLAN
------------------------------------------------------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_date
Recheck Cond: (i < 'Tue Oct 26 00:00:00 2004 PDT'::timestamp with time zone)
-> Bitmap Index Scan on idx_date
Index Cond: (i < 'Tue Oct 26 00:00:00 2004 PDT'::timestamp with time zone)
(6 rows)
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamptz ORDER BY i;
i
------------
10-23-2004
10-24-2004
10-25-2004
(3 rows)
SELECT * FROM test_date WHERE i<='2004-10-26'::timestamptz ORDER BY i;
i
------------
10-23-2004
10-24-2004
10-25-2004
10-26-2004
(4 rows)
SELECT * FROM test_date WHERE i='2004-10-26'::timestamptz ORDER BY i;
i
------------
10-26-2004
(1 row)
SELECT * FROM test_date WHERE i>='2004-10-26'::timestamptz ORDER BY i;
i
------------
10-26-2004
10-27-2004
10-28-2004
(3 rows)
SELECT * FROM test_date WHERE i>'2004-10-26'::timestamptz ORDER BY i;
i
------------
10-27-2004
10-28-2004
(2 rows)
-- Check endpoint and out-of-range cases
INSERT INTO test_date VALUES ('-infinity'), ('infinity');
SELECT gin_clean_pending_list('idx_date');
gin_clean_pending_list
------------------------
1
(1 row)
SELECT * FROM test_date WHERE i<'-infinity'::timestamp ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_date WHERE i<='-infinity'::timestamp ORDER BY i;
i
-----------
-infinity
(1 row)
SELECT * FROM test_date WHERE i='-infinity'::timestamp ORDER BY i;
i
-----------
-infinity
(1 row)
SELECT * FROM test_date WHERE i>='-infinity'::timestamp ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
10-26-2004
10-27-2004
10-28-2004
infinity
(8 rows)
SELECT * FROM test_date WHERE i>'-infinity'::timestamp ORDER BY i;
i
------------
10-23-2004
10-24-2004
10-25-2004
10-26-2004
10-27-2004
10-28-2004
infinity
(7 rows)
SELECT * FROM test_date WHERE i<'infinity'::timestamp ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
10-26-2004
10-27-2004
10-28-2004
(7 rows)
SELECT * FROM test_date WHERE i<='infinity'::timestamp ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
10-26-2004
10-27-2004
10-28-2004
infinity
(8 rows)
SELECT * FROM test_date WHERE i='infinity'::timestamp ORDER BY i;
i
----------
infinity
(1 row)
SELECT * FROM test_date WHERE i>='infinity'::timestamp ORDER BY i;
i
----------
infinity
(1 row)
SELECT * FROM test_date WHERE i>'infinity'::timestamp ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_date WHERE i<'-infinity'::timestamptz ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_date WHERE i<='-infinity'::timestamptz ORDER BY i;
i
-----------
-infinity
(1 row)
SELECT * FROM test_date WHERE i='-infinity'::timestamptz ORDER BY i;
i
-----------
-infinity
(1 row)
SELECT * FROM test_date WHERE i>='-infinity'::timestamptz ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
10-26-2004
10-27-2004
10-28-2004
infinity
(8 rows)
SELECT * FROM test_date WHERE i>'-infinity'::timestamptz ORDER BY i;
i
------------
10-23-2004
10-24-2004
10-25-2004
10-26-2004
10-27-2004
10-28-2004
infinity
(7 rows)
SELECT * FROM test_date WHERE i<'infinity'::timestamptz ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
10-26-2004
10-27-2004
10-28-2004
(7 rows)
SELECT * FROM test_date WHERE i<='infinity'::timestamptz ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
10-26-2004
10-27-2004
10-28-2004
infinity
(8 rows)
SELECT * FROM test_date WHERE i='infinity'::timestamptz ORDER BY i;
i
----------
infinity
(1 row)
SELECT * FROM test_date WHERE i>='infinity'::timestamptz ORDER BY i;
i
----------
infinity
(1 row)
SELECT * FROM test_date WHERE i>'infinity'::timestamptz ORDER BY i;
i
---
(0 rows)
-- Check rounding cases
-- '2004-10-25 00:00:01' rounds to '2004-10-25' for date.
-- '2004-10-25 23:59:59' also rounds to '2004-10-25',
-- so it's the same case as '2004-10-25 00:00:01'
SELECT * FROM test_date WHERE i < '2004-10-25 00:00:01'::timestamp ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
(4 rows)
SELECT * FROM test_date WHERE i <= '2004-10-25 00:00:01'::timestamp ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
(4 rows)
SELECT * FROM test_date WHERE i = '2004-10-25 00:00:01'::timestamp ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_date WHERE i > '2004-10-25 00:00:01'::timestamp ORDER BY i;
i
------------
10-26-2004
10-27-2004
10-28-2004
infinity
(4 rows)
SELECT * FROM test_date WHERE i >= '2004-10-25 00:00:01'::timestamp ORDER BY i;
i
------------
10-26-2004
10-27-2004
10-28-2004
infinity
(4 rows)
SELECT * FROM test_date WHERE i < '2004-10-25 00:00:01'::timestamptz ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
(4 rows)
SELECT * FROM test_date WHERE i <= '2004-10-25 00:00:01'::timestamptz ORDER BY i;
i
------------
-infinity
10-23-2004
10-24-2004
10-25-2004
(4 rows)
SELECT * FROM test_date WHERE i = '2004-10-25 00:00:01'::timestamptz ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_date WHERE i > '2004-10-25 00:00:01'::timestamptz ORDER BY i;
i
------------
10-26-2004
10-27-2004
10-28-2004
infinity
(4 rows)
SELECT * FROM test_date WHERE i >= '2004-10-25 00:00:01'::timestamptz ORDER BY i;
i
------------
10-26-2004
10-27-2004
10-28-2004
infinity
(4 rows)

View File

@@ -42,3 +42,324 @@ SELECT * FROM test_float4 WHERE i>1::float4 ORDER BY i;
3
(2 rows)
explain (costs off)
SELECT * FROM test_float4 WHERE i<1::float8 ORDER BY i;
QUERY PLAN
-------------------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_float4
Recheck Cond: (i < '1'::double precision)
-> Bitmap Index Scan on idx_float4
Index Cond: (i < '1'::double precision)
(6 rows)
SELECT * FROM test_float4 WHERE i<1::float8 ORDER BY i;
i
----
-2
-1
0
(3 rows)
SELECT * FROM test_float4 WHERE i<=1::float8 ORDER BY i;
i
----
-2
-1
0
1
(4 rows)
SELECT * FROM test_float4 WHERE i=1::float8 ORDER BY i;
i
---
1
(1 row)
SELECT * FROM test_float4 WHERE i>=1::float8 ORDER BY i;
i
---
1
2
3
(3 rows)
SELECT * FROM test_float4 WHERE i>1::float8 ORDER BY i;
i
---
2
3
(2 rows)
-- Check endpoint and out-of-range cases
INSERT INTO test_float4 VALUES ('NaN'), ('Inf'), ('-Inf');
SELECT gin_clean_pending_list('idx_float4');
gin_clean_pending_list
------------------------
1
(1 row)
SELECT * FROM test_float4 WHERE i<'-Inf'::float8 ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_float4 WHERE i<='-Inf'::float8 ORDER BY i;
i
-----------
-Infinity
(1 row)
SELECT * FROM test_float4 WHERE i='-Inf'::float8 ORDER BY i;
i
-----------
-Infinity
(1 row)
SELECT * FROM test_float4 WHERE i>='-Inf'::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
0
1
2
3
Infinity
NaN
(9 rows)
SELECT * FROM test_float4 WHERE i>'-Inf'::float8 ORDER BY i;
i
----------
-2
-1
0
1
2
3
Infinity
NaN
(8 rows)
SELECT * FROM test_float4 WHERE i<'Inf'::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
0
1
2
3
(7 rows)
SELECT * FROM test_float4 WHERE i<='Inf'::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
0
1
2
3
Infinity
(8 rows)
SELECT * FROM test_float4 WHERE i='Inf'::float8 ORDER BY i;
i
----------
Infinity
(1 row)
SELECT * FROM test_float4 WHERE i>='Inf'::float8 ORDER BY i;
i
----------
Infinity
NaN
(2 rows)
SELECT * FROM test_float4 WHERE i>'Inf'::float8 ORDER BY i;
i
-----
NaN
(1 row)
SELECT * FROM test_float4 WHERE i<'1e300'::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
0
1
2
3
(7 rows)
SELECT * FROM test_float4 WHERE i<='1e300'::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
0
1
2
3
(7 rows)
SELECT * FROM test_float4 WHERE i='1e300'::float8 ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_float4 WHERE i>='1e300'::float8 ORDER BY i;
i
----------
Infinity
NaN
(2 rows)
SELECT * FROM test_float4 WHERE i>'1e300'::float8 ORDER BY i;
i
----------
Infinity
NaN
(2 rows)
SELECT * FROM test_float4 WHERE i<'NaN'::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
0
1
2
3
Infinity
(8 rows)
SELECT * FROM test_float4 WHERE i<='NaN'::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
0
1
2
3
Infinity
NaN
(9 rows)
SELECT * FROM test_float4 WHERE i='NaN'::float8 ORDER BY i;
i
-----
NaN
(1 row)
SELECT * FROM test_float4 WHERE i>='NaN'::float8 ORDER BY i;
i
-----
NaN
(1 row)
SELECT * FROM test_float4 WHERE i>'NaN'::float8 ORDER BY i;
i
---
(0 rows)
-- Check rounding cases
-- 1e-300 rounds to 0 for float4 but not for float8
SELECT * FROM test_float4 WHERE i < -1e-300::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
(3 rows)
SELECT * FROM test_float4 WHERE i <= -1e-300::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
(3 rows)
SELECT * FROM test_float4 WHERE i = -1e-300::float8 ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_float4 WHERE i > -1e-300::float8 ORDER BY i;
i
----------
0
1
2
3
Infinity
NaN
(6 rows)
SELECT * FROM test_float4 WHERE i >= -1e-300::float8 ORDER BY i;
i
----------
0
1
2
3
Infinity
NaN
(6 rows)
SELECT * FROM test_float4 WHERE i < 1e-300::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
0
(4 rows)
SELECT * FROM test_float4 WHERE i <= 1e-300::float8 ORDER BY i;
i
-----------
-Infinity
-2
-1
0
(4 rows)
SELECT * FROM test_float4 WHERE i = 1e-300::float8 ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_float4 WHERE i > 1e-300::float8 ORDER BY i;
i
----------
1
2
3
Infinity
NaN
(5 rows)
SELECT * FROM test_float4 WHERE i >= 1e-300::float8 ORDER BY i;
i
----------
1
2
3
Infinity
NaN
(5 rows)

View File

@@ -42,3 +42,53 @@ SELECT * FROM test_float8 WHERE i>1::float8 ORDER BY i;
3
(2 rows)
explain (costs off)
SELECT * FROM test_float8 WHERE i<1::float4 ORDER BY i;
QUERY PLAN
---------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_float8
Recheck Cond: (i < '1'::real)
-> Bitmap Index Scan on idx_float8
Index Cond: (i < '1'::real)
(6 rows)
SELECT * FROM test_float8 WHERE i<1::float4 ORDER BY i;
i
----
-2
-1
0
(3 rows)
SELECT * FROM test_float8 WHERE i<=1::float4 ORDER BY i;
i
----
-2
-1
0
1
(4 rows)
SELECT * FROM test_float8 WHERE i=1::float4 ORDER BY i;
i
---
1
(1 row)
SELECT * FROM test_float8 WHERE i>=1::float4 ORDER BY i;
i
---
1
2
3
(3 rows)
SELECT * FROM test_float8 WHERE i>1::float4 ORDER BY i;
i
---
2
3
(2 rows)

View File

@@ -95,3 +95,62 @@ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
Index Cond: (i > 'abc'::name)
(6 rows)
explain (costs off)
SELECT * FROM test_name WHERE i<'abc'::text ORDER BY i;
QUERY PLAN
---------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_name
Recheck Cond: (i < 'abc'::text)
-> Bitmap Index Scan on idx_name
Index Cond: (i < 'abc'::text)
(6 rows)
SELECT * FROM test_name WHERE i<'abc'::text ORDER BY i;
i
-----
a
ab
abb
(3 rows)
SELECT * FROM test_name WHERE i<='abc'::text ORDER BY i;
i
-----
a
ab
abb
abc
(4 rows)
SELECT * FROM test_name WHERE i='abc'::text ORDER BY i;
i
-----
abc
(1 row)
SELECT * FROM test_name WHERE i>='abc'::text ORDER BY i;
i
-----
abc
axy
xyz
(3 rows)
SELECT * FROM test_name WHERE i>'abc'::text ORDER BY i;
i
-----
axy
xyz
(2 rows)
SELECT * FROM test_name WHERE i<=repeat('abc', 100) ORDER BY i;
i
-----
a
ab
abb
abc
(4 rows)

View File

@@ -42,3 +42,53 @@ SELECT * FROM test_text WHERE i>'abc' ORDER BY i;
xyz
(2 rows)
explain (costs off)
SELECT * FROM test_text WHERE i<'abc'::name COLLATE "default" ORDER BY i;
QUERY PLAN
---------------------------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_text
Recheck Cond: (i < 'abc'::name COLLATE "default")
-> Bitmap Index Scan on idx_text
Index Cond: (i < 'abc'::name COLLATE "default")
(6 rows)
SELECT * FROM test_text WHERE i<'abc'::name COLLATE "default" ORDER BY i;
i
-----
a
ab
abb
(3 rows)
SELECT * FROM test_text WHERE i<='abc'::name COLLATE "default" ORDER BY i;
i
-----
a
ab
abb
abc
(4 rows)
SELECT * FROM test_text WHERE i='abc'::name COLLATE "default" ORDER BY i;
i
-----
abc
(1 row)
SELECT * FROM test_text WHERE i>='abc'::name COLLATE "default" ORDER BY i;
i
-----
abc
axy
xyz
(3 rows)
SELECT * FROM test_text WHERE i>'abc'::name COLLATE "default" ORDER BY i;
i
-----
axy
xyz
(2 rows)

View File

@@ -7,8 +7,8 @@ INSERT INTO test_timestamp VALUES
( '2004-10-26 04:55:08' ),
( '2004-10-26 05:55:08' ),
( '2004-10-26 08:55:08' ),
( '2004-10-26 09:55:08' ),
( '2004-10-26 10:55:08' )
( '2004-10-27 09:55:08' ),
( '2004-10-27 10:55:08' )
;
CREATE INDEX idx_timestamp ON test_timestamp USING gin (i);
SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
@@ -38,14 +38,308 @@ SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY
i
--------------------------
Tue Oct 26 08:55:08 2004
Tue Oct 26 09:55:08 2004
Tue Oct 26 10:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
(3 rows)
SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamp ORDER BY i;
i
--------------------------
Tue Oct 26 09:55:08 2004
Tue Oct 26 10:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
(2 rows)
explain (costs off)
SELECT * FROM test_timestamp WHERE i<'2004-10-27'::date ORDER BY i;
QUERY PLAN
----------------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_timestamp
Recheck Cond: (i < '10-27-2004'::date)
-> Bitmap Index Scan on idx_timestamp
Index Cond: (i < '10-27-2004'::date)
(6 rows)
SELECT * FROM test_timestamp WHERE i<'2004-10-27'::date ORDER BY i;
i
--------------------------
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
(4 rows)
SELECT * FROM test_timestamp WHERE i<='2004-10-27'::date ORDER BY i;
i
--------------------------
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
(4 rows)
SELECT * FROM test_timestamp WHERE i='2004-10-27'::date ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_timestamp WHERE i>='2004-10-27'::date ORDER BY i;
i
--------------------------
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
(2 rows)
SELECT * FROM test_timestamp WHERE i>'2004-10-27'::date ORDER BY i;
i
--------------------------
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
(2 rows)
explain (costs off)
SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamptz ORDER BY i;
QUERY PLAN
------------------------------------------------------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_timestamp
Recheck Cond: (i < 'Tue Oct 26 08:55:08 2004 PDT'::timestamp with time zone)
-> Bitmap Index Scan on idx_timestamp
Index Cond: (i < 'Tue Oct 26 08:55:08 2004 PDT'::timestamp with time zone)
(6 rows)
SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamptz ORDER BY i;
i
--------------------------
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
(3 rows)
SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamptz ORDER BY i;
i
--------------------------
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
(4 rows)
SELECT * FROM test_timestamp WHERE i='2004-10-26 08:55:08'::timestamptz ORDER BY i;
i
--------------------------
Tue Oct 26 08:55:08 2004
(1 row)
SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamptz ORDER BY i;
i
--------------------------
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
(3 rows)
SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamptz ORDER BY i;
i
--------------------------
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
(2 rows)
-- Check endpoint and out-of-range cases
INSERT INTO test_timestamp VALUES ('-infinity'), ('infinity');
SELECT gin_clean_pending_list('idx_timestamp');
gin_clean_pending_list
------------------------
1
(1 row)
SELECT * FROM test_timestamp WHERE i<'-infinity'::date ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_timestamp WHERE i<='-infinity'::date ORDER BY i;
i
-----------
-infinity
(1 row)
SELECT * FROM test_timestamp WHERE i='-infinity'::date ORDER BY i;
i
-----------
-infinity
(1 row)
SELECT * FROM test_timestamp WHERE i>='-infinity'::date ORDER BY i;
i
--------------------------
-infinity
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
infinity
(8 rows)
SELECT * FROM test_timestamp WHERE i>'-infinity'::date ORDER BY i;
i
--------------------------
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
infinity
(7 rows)
SELECT * FROM test_timestamp WHERE i<'infinity'::date ORDER BY i;
i
--------------------------
-infinity
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
(7 rows)
SELECT * FROM test_timestamp WHERE i<='infinity'::date ORDER BY i;
i
--------------------------
-infinity
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
infinity
(8 rows)
SELECT * FROM test_timestamp WHERE i='infinity'::date ORDER BY i;
i
----------
infinity
(1 row)
SELECT * FROM test_timestamp WHERE i>='infinity'::date ORDER BY i;
i
----------
infinity
(1 row)
SELECT * FROM test_timestamp WHERE i>'infinity'::date ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_timestamp WHERE i<'-infinity'::timestamptz ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_timestamp WHERE i<='-infinity'::timestamptz ORDER BY i;
i
-----------
-infinity
(1 row)
SELECT * FROM test_timestamp WHERE i='-infinity'::timestamptz ORDER BY i;
i
-----------
-infinity
(1 row)
SELECT * FROM test_timestamp WHERE i>='-infinity'::timestamptz ORDER BY i;
i
--------------------------
-infinity
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
infinity
(8 rows)
SELECT * FROM test_timestamp WHERE i>'-infinity'::timestamptz ORDER BY i;
i
--------------------------
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
infinity
(7 rows)
SELECT * FROM test_timestamp WHERE i<'infinity'::timestamptz ORDER BY i;
i
--------------------------
-infinity
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
(7 rows)
SELECT * FROM test_timestamp WHERE i<='infinity'::timestamptz ORDER BY i;
i
--------------------------
-infinity
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
infinity
(8 rows)
SELECT * FROM test_timestamp WHERE i='infinity'::timestamptz ORDER BY i;
i
----------
infinity
(1 row)
SELECT * FROM test_timestamp WHERE i>='infinity'::timestamptz ORDER BY i;
i
----------
infinity
(1 row)
SELECT * FROM test_timestamp WHERE i>'infinity'::timestamptz ORDER BY i;
i
---
(0 rows)
-- This PST timestamptz will underflow if converted to timestamp
SELECT * FROM test_timestamp WHERE i<='4714-11-23 17:00 BC'::timestamptz ORDER BY i;
i
-----------
-infinity
(1 row)
SELECT * FROM test_timestamp WHERE i>'4714-11-23 17:00 BC'::timestamptz ORDER BY i;
i
--------------------------
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
Wed Oct 27 09:55:08 2004
Wed Oct 27 10:55:08 2004
infinity
(7 rows)

View File

@@ -7,8 +7,8 @@ INSERT INTO test_timestamptz VALUES
( '2004-10-26 04:55:08' ),
( '2004-10-26 05:55:08' ),
( '2004-10-26 08:55:08' ),
( '2004-10-26 09:55:08' ),
( '2004-10-26 10:55:08' )
( '2004-10-27 09:55:08' ),
( '2004-10-27 10:55:08' )
;
CREATE INDEX idx_timestamptz ON test_timestamptz USING gin (i);
SELECT * FROM test_timestamptz WHERE i<'2004-10-26 08:55:08'::timestamptz ORDER BY i;
@@ -38,14 +38,113 @@ SELECT * FROM test_timestamptz WHERE i>='2004-10-26 08:55:08'::timestamptz ORDER
i
------------------------------
Tue Oct 26 08:55:08 2004 PDT
Tue Oct 26 09:55:08 2004 PDT
Tue Oct 26 10:55:08 2004 PDT
Wed Oct 27 09:55:08 2004 PDT
Wed Oct 27 10:55:08 2004 PDT
(3 rows)
SELECT * FROM test_timestamptz WHERE i>'2004-10-26 08:55:08'::timestamptz ORDER BY i;
i
------------------------------
Tue Oct 26 09:55:08 2004 PDT
Tue Oct 26 10:55:08 2004 PDT
Wed Oct 27 09:55:08 2004 PDT
Wed Oct 27 10:55:08 2004 PDT
(2 rows)
explain (costs off)
SELECT * FROM test_timestamptz WHERE i<'2004-10-27'::date ORDER BY i;
QUERY PLAN
----------------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_timestamptz
Recheck Cond: (i < '10-27-2004'::date)
-> Bitmap Index Scan on idx_timestamptz
Index Cond: (i < '10-27-2004'::date)
(6 rows)
SELECT * FROM test_timestamptz WHERE i<'2004-10-27'::date ORDER BY i;
i
------------------------------
Tue Oct 26 03:55:08 2004 PDT
Tue Oct 26 04:55:08 2004 PDT
Tue Oct 26 05:55:08 2004 PDT
Tue Oct 26 08:55:08 2004 PDT
(4 rows)
SELECT * FROM test_timestamptz WHERE i<='2004-10-27'::date ORDER BY i;
i
------------------------------
Tue Oct 26 03:55:08 2004 PDT
Tue Oct 26 04:55:08 2004 PDT
Tue Oct 26 05:55:08 2004 PDT
Tue Oct 26 08:55:08 2004 PDT
(4 rows)
SELECT * FROM test_timestamptz WHERE i='2004-10-27'::date ORDER BY i;
i
---
(0 rows)
SELECT * FROM test_timestamptz WHERE i>='2004-10-27'::date ORDER BY i;
i
------------------------------
Wed Oct 27 09:55:08 2004 PDT
Wed Oct 27 10:55:08 2004 PDT
(2 rows)
SELECT * FROM test_timestamptz WHERE i>'2004-10-27'::date ORDER BY i;
i
------------------------------
Wed Oct 27 09:55:08 2004 PDT
Wed Oct 27 10:55:08 2004 PDT
(2 rows)
explain (costs off)
SELECT * FROM test_timestamptz WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
QUERY PLAN
-----------------------------------------------------------------------------------------
Sort
Sort Key: i
-> Bitmap Heap Scan on test_timestamptz
Recheck Cond: (i < 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
-> Bitmap Index Scan on idx_timestamptz
Index Cond: (i < 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
(6 rows)
SELECT * FROM test_timestamptz WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
i
------------------------------
Tue Oct 26 03:55:08 2004 PDT
Tue Oct 26 04:55:08 2004 PDT
Tue Oct 26 05:55:08 2004 PDT
(3 rows)
SELECT * FROM test_timestamptz WHERE i<='2004-10-26 08:55:08'::timestamp ORDER BY i;
i
------------------------------
Tue Oct 26 03:55:08 2004 PDT
Tue Oct 26 04:55:08 2004 PDT
Tue Oct 26 05:55:08 2004 PDT
Tue Oct 26 08:55:08 2004 PDT
(4 rows)
SELECT * FROM test_timestamptz WHERE i='2004-10-26 08:55:08'::timestamp ORDER BY i;
i
------------------------------
Tue Oct 26 08:55:08 2004 PDT
(1 row)
SELECT * FROM test_timestamptz WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY i;
i
------------------------------
Tue Oct 26 08:55:08 2004 PDT
Wed Oct 27 09:55:08 2004 PDT
Wed Oct 27 10:55:08 2004 PDT
(3 rows)
SELECT * FROM test_timestamptz WHERE i>'2004-10-26 08:55:08'::timestamp ORDER BY i;
i
------------------------------
Wed Oct 27 09:55:08 2004 PDT
Wed Oct 27 10:55:08 2004 PDT
(2 rows)