📄 horology.sql
字号:
OVERLAPS (timestamp with time zone '2000-11-27', interval '12 hours') AS "True";SELECT (timestamp with time zone '2000-11-27', interval '12 hours') OVERLAPS (timestamp with time zone '2000-11-27 12:00', interval '12 hours') AS "False";-- test without time zoneSELECT (timestamp without time zone '2000-11-27', timestamp without time zone '2000-11-28') OVERLAPS (timestamp without time zone '2000-11-27 12:00', timestamp without time zone '2000-11-30') AS "True";SELECT (timestamp without time zone '2000-11-26', timestamp without time zone '2000-11-27') OVERLAPS (timestamp without time zone '2000-11-27 12:00', timestamp without time zone '2000-11-30') AS "False";SELECT (timestamp without time zone '2000-11-27', timestamp without time zone '2000-11-28') OVERLAPS (timestamp without time zone '2000-11-27 12:00', interval '1 day') AS "True";SELECT (timestamp without time zone '2000-11-27', interval '12 hours') OVERLAPS (timestamp without time zone '2000-11-27 12:00', timestamp without time zone '2000-11-30') AS "False";SELECT (timestamp without time zone '2000-11-27', interval '12 hours') OVERLAPS (timestamp without time zone '2000-11-27', interval '12 hours') AS "True";SELECT (timestamp without time zone '2000-11-27', interval '12 hours') OVERLAPS (timestamp without time zone '2000-11-27 12:00', interval '12 hours') AS "False";-- test time and intervalSELECT (time '00:00', time '01:00') OVERLAPS (time '00:30', time '01:30') AS "True";SELECT (time '00:00', interval '1 hour') OVERLAPS (time '00:30', interval '1 hour') AS "True";SELECT (time '00:00', interval '1 hour') OVERLAPS (time '01:30', interval '1 hour') AS "False";-- SQL99 seems to want this to be false (and we conform to the spec).-- istm that this *should* return true, on the theory that time-- intervals can wrap around the day boundary - thomas 2001-09-25SELECT (time '00:00', interval '1 hour') OVERLAPS (time '01:30', interval '1 day') AS "False";CREATE TABLE TEMP_TIMESTAMP (f1 timestamp with time zone);-- get some candidate input valuesINSERT INTO TEMP_TIMESTAMP (f1) SELECT d1 FROM TIMESTAMP_TBL WHERE d1 BETWEEN '13-jun-1957' AND '1-jan-1997' OR d1 BETWEEN '1-jan-1999' AND '1-jan-2010';SELECT '' AS "16", f1 AS "timestamp" FROM TEMP_TIMESTAMP ORDER BY "timestamp";SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 + t.f1 AS plus FROM TEMP_TIMESTAMP d, INTERVAL_TBL t ORDER BY plus, "timestamp", "interval";SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 - t.f1 AS minus FROM TEMP_TIMESTAMP d, INTERVAL_TBL t WHERE isfinite(d.f1) ORDER BY minus, "timestamp", "interval";SELECT '' AS "16", d.f1 AS "timestamp", timestamp with time zone '1980-01-06 00:00 GMT' AS gpstime_zero, d.f1 - timestamp with time zone '1980-01-06 00:00 GMT' AS difference FROM TEMP_TIMESTAMP d ORDER BY difference;SELECT '' AS "226", d1.f1 AS timestamp1, d2.f1 AS timestamp2, d1.f1 - d2.f1 AS difference FROM TEMP_TIMESTAMP d1, TEMP_TIMESTAMP d2 ORDER BY timestamp1, timestamp2, difference;---- abstime, reltime arithmetic--SELECT '' AS ten, ABSTIME_TBL.f1 AS abstime, RELTIME_TBL.f1 AS reltime FROM ABSTIME_TBL, RELTIME_TBL WHERE (ABSTIME_TBL.f1 + RELTIME_TBL.f1) < abstime 'Jan 14 14:00:00 1971' ORDER BY abstime, reltime;-- these four queries should return the same answer-- the "infinity" and "-infinity" tuples in ABSTIME_TBL cannot be added and-- therefore, should not show up in the results.SELECT '' AS three, * FROM ABSTIME_TBL WHERE (ABSTIME_TBL.f1 + reltime '@ 3 year') -- +3 years < abstime 'Jan 14 14:00:00 1977';SELECT '' AS three, * FROM ABSTIME_TBL WHERE (ABSTIME_TBL.f1 + reltime '@ 3 year ago') -- -3 years < abstime 'Jan 14 14:00:00 1971';SELECT '' AS three, * FROM ABSTIME_TBL WHERE (ABSTIME_TBL.f1 - reltime '@ 3 year') -- -(+3) years < abstime 'Jan 14 14:00:00 1971';SELECT '' AS three, * FROM ABSTIME_TBL WHERE (ABSTIME_TBL.f1 - reltime '@ 3 year ago') -- -(-3) years < abstime 'Jan 14 14:00:00 1977';---- Conversions--SELECT '' AS "16", f1 AS "timestamp", date(f1) AS date FROM TEMP_TIMESTAMP WHERE f1 <> timestamp 'now' ORDER BY date, "timestamp";SELECT '' AS "16", f1 AS "timestamp", abstime(f1) AS abstime FROM TEMP_TIMESTAMP ORDER BY abstime;SELECT '' AS four, f1 AS abstime, date(f1) AS date FROM ABSTIME_TBL WHERE isfinite(f1) AND f1 <> abstime 'now' ORDER BY date, abstime;SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime FROM TIMESTAMP_TBL WHERE NOT isfinite(d1);SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp" FROM ABSTIME_TBL WHERE NOT isfinite(f1);SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime FROM INTERVAL_TBL;SELECT '' AS six, f1 as reltime, CAST(f1 AS interval) AS interval FROM RELTIME_TBL;DROP TABLE TEMP_TIMESTAMP;---- Formats--SET DateStyle TO 'US,Postgres';SHOW DateStyle;SELECT '' AS "64", d1 AS us_postgres FROM TIMESTAMP_TBL;SELECT '' AS seven, f1 AS us_postgres FROM ABSTIME_TBL;SET DateStyle TO 'US,ISO';SELECT '' AS "64", d1 AS us_iso FROM TIMESTAMP_TBL;SELECT '' AS seven, f1 AS us_iso FROM ABSTIME_TBL;SET DateStyle TO 'US,SQL';SHOW DateStyle;SELECT '' AS "64", d1 AS us_sql FROM TIMESTAMP_TBL;SELECT '' AS seven, f1 AS us_sql FROM ABSTIME_TBL;SET DateStyle TO 'European,Postgres';SHOW DateStyle;INSERT INTO TIMESTAMP_TBL VALUES('13/06/1957');SELECT count(*) as one FROM TIMESTAMP_TBL WHERE d1 = 'Jun 13 1957';SELECT '' AS "65", d1 AS european_postgres FROM TIMESTAMP_TBL;SELECT '' AS seven, f1 AS european_postgres FROM ABSTIME_TBL;SET DateStyle TO 'European,ISO';SHOW DateStyle;SELECT '' AS "65", d1 AS european_iso FROM TIMESTAMP_TBL;SELECT '' AS seven, f1 AS european_iso FROM ABSTIME_TBL;SET DateStyle TO 'European,SQL';SHOW DateStyle;SELECT '' AS "65", d1 AS european_sql FROM TIMESTAMP_TBL;SELECT '' AS seven, f1 AS european_sql FROM ABSTIME_TBL;RESET DateStyle;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -