1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-24 14:22:24 +03:00
Files
postgres/contrib/btree_gin/sql/date.sql
Tom Lane fc896821c4 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
2025-07-03 16:30:38 -04:00

87 lines
3.9 KiB
SQL

set enable_seqscan=off;
CREATE TABLE test_date (
i date
);
INSERT INTO test_date VALUES
( '2004-10-23' ),
( '2004-10-24' ),
( '2004-10-25' ),
( '2004-10-26' ),
( '2004-10-27' ),
( '2004-10-28' )
;
CREATE INDEX idx_date ON test_date USING gin (i);
SELECT * FROM test_date WHERE i<'2004-10-26'::date ORDER BY i;
SELECT * FROM test_date WHERE i<='2004-10-26'::date ORDER BY i;
SELECT * FROM test_date WHERE i='2004-10-26'::date ORDER BY i;
SELECT * FROM test_date WHERE i>='2004-10-26'::date ORDER BY i;
SELECT * FROM test_date WHERE i>'2004-10-26'::date ORDER BY i;
explain (costs off)
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i<='2004-10-26'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i='2004-10-26'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i>='2004-10-26'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i>'2004-10-26'::timestamp ORDER BY i;
explain (costs off)
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i<='2004-10-26'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i='2004-10-26'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i>='2004-10-26'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i>'2004-10-26'::timestamptz ORDER BY i;
-- Check endpoint and out-of-range cases
INSERT INTO test_date VALUES ('-infinity'), ('infinity');
SELECT gin_clean_pending_list('idx_date');
SELECT * FROM test_date WHERE i<'-infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i<='-infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i='-infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i>='-infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i>'-infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i<'infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i<='infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i='infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i>='infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i>'infinity'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i<'-infinity'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i<='-infinity'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i='-infinity'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i>='-infinity'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i>'-infinity'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i<'infinity'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i<='infinity'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i='infinity'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i>='infinity'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i>'infinity'::timestamptz ORDER BY i;
-- 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;
SELECT * FROM test_date WHERE i <= '2004-10-25 00:00:01'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i = '2004-10-25 00:00:01'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i > '2004-10-25 00:00:01'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i >= '2004-10-25 00:00:01'::timestamp ORDER BY i;
SELECT * FROM test_date WHERE i < '2004-10-25 00:00:01'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i <= '2004-10-25 00:00:01'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i = '2004-10-25 00:00:01'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i > '2004-10-25 00:00:01'::timestamptz ORDER BY i;
SELECT * FROM test_date WHERE i >= '2004-10-25 00:00:01'::timestamptz ORDER BY i;