mirror of https://github.com/postgres/postgres
These types have been deprecated for a *long* time. Catversion bump, for obvious reasons. Author: Andres Freund Discussion: https://postgr.es/m/20181009192237.34wjp3nmw7oynmmr@alap3.anarazel.de https://postgr.es/m/20171213080506.cwjkpcz3bkk6yz2u@alap3.anarazel.de https://postgr.es/m/25615.1513115237@sss.pgh.pa.uspull/34/head
parent
2d10defa77
commit
cda6a8d01d
File diff suppressed because it is too large
Load Diff
@ -1,103 +0,0 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* nabstime.h |
||||
* Definitions for the "new" abstime code. |
||||
* |
||||
* |
||||
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* src/include/utils/nabstime.h |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef NABSTIME_H |
||||
#define NABSTIME_H |
||||
|
||||
#include <limits.h> |
||||
|
||||
#include "fmgr.h" |
||||
#include "pgtime.h" |
||||
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* |
||||
* time types + support macros |
||||
* |
||||
* ---------------------------------------------------------------- |
||||
*/ |
||||
|
||||
/*
|
||||
* Although time_t generally is a long int on 64 bit systems, these two |
||||
* types must be 4 bytes, because that's what pg_type.h assumes. They |
||||
* should be yanked (long) before 2038 and be replaced by timestamp and |
||||
* interval. |
||||
*/ |
||||
typedef int32 AbsoluteTime; |
||||
typedef int32 RelativeTime; |
||||
|
||||
typedef struct |
||||
{ |
||||
int32 status; |
||||
AbsoluteTime data[2]; |
||||
} TimeIntervalData; |
||||
|
||||
typedef TimeIntervalData *TimeInterval; |
||||
|
||||
/*
|
||||
* Macros for fmgr-callable functions. |
||||
*/ |
||||
#define DatumGetAbsoluteTime(X) ((AbsoluteTime) DatumGetInt32(X)) |
||||
#define DatumGetRelativeTime(X) ((RelativeTime) DatumGetInt32(X)) |
||||
#define DatumGetTimeInterval(X) ((TimeInterval) DatumGetPointer(X)) |
||||
|
||||
#define AbsoluteTimeGetDatum(X) Int32GetDatum(X) |
||||
#define RelativeTimeGetDatum(X) Int32GetDatum(X) |
||||
#define TimeIntervalGetDatum(X) PointerGetDatum(X) |
||||
|
||||
#define PG_GETARG_ABSOLUTETIME(n) DatumGetAbsoluteTime(PG_GETARG_DATUM(n)) |
||||
#define PG_GETARG_RELATIVETIME(n) DatumGetRelativeTime(PG_GETARG_DATUM(n)) |
||||
#define PG_GETARG_TIMEINTERVAL(n) DatumGetTimeInterval(PG_GETARG_DATUM(n)) |
||||
|
||||
#define PG_RETURN_ABSOLUTETIME(x) return AbsoluteTimeGetDatum(x) |
||||
#define PG_RETURN_RELATIVETIME(x) return RelativeTimeGetDatum(x) |
||||
#define PG_RETURN_TIMEINTERVAL(x) return TimeIntervalGetDatum(x) |
||||
|
||||
/*
|
||||
* Reserved values |
||||
* Epoch is Unix system time zero, but needs to be kept as a reserved |
||||
* value rather than converting to time since timezone calculations |
||||
* might move it away from 1970-01-01 00:00:00Z - tgl 97/02/20 |
||||
* |
||||
* Pre-v6.1 code had large decimal numbers for reserved values. |
||||
* These were chosen as special 32-bit bit patterns, |
||||
* so redefine them explicitly using these bit patterns. - tgl 97/02/24 |
||||
*/ |
||||
#define INVALID_ABSTIME ((AbsoluteTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */ |
||||
#define NOEND_ABSTIME ((AbsoluteTime) 0x7FFFFFFC) /* 2147483645 (2^31 - 3) */ |
||||
#define NOSTART_ABSTIME ((AbsoluteTime) INT_MIN) /* -2147483648 */ |
||||
|
||||
#define INVALID_RELTIME ((RelativeTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */ |
||||
|
||||
#define AbsoluteTimeIsValid(time) \ |
||||
((bool) ((time) != INVALID_ABSTIME)) |
||||
|
||||
/*
|
||||
* Because NOSTART_ABSTIME is defined as INT_MIN, there can't be any |
||||
* AbsoluteTime values less than it. Therefore, we can code the test |
||||
* "time > NOSTART_ABSTIME" as "time != NOSTART_ABSTIME", which avoids |
||||
* compiler bugs on some platforms. --- tgl & az, 11/2000 |
||||
*/ |
||||
#define AbsoluteTimeIsReal(time) \ |
||||
((bool) (((AbsoluteTime) (time)) < NOEND_ABSTIME && \
|
||||
((AbsoluteTime) (time)) != NOSTART_ABSTIME)) |
||||
|
||||
#define RelativeTimeIsValid(time) \ |
||||
((bool) (((RelativeTime) (time)) != INVALID_RELTIME)) |
||||
|
||||
|
||||
/* non-fmgr-callable support routines */ |
||||
extern AbsoluteTime GetCurrentAbsoluteTime(void); |
||||
extern void abstime2tm(AbsoluteTime time, int *tzp, struct pg_tm *tm, char **tzn); |
||||
|
||||
#endif /* NABSTIME_H */ |
@ -1,136 +0,0 @@ |
||||
-- |
||||
-- ABSTIME |
||||
-- testing built-in time type abstime |
||||
-- uses reltime and tinterval |
||||
-- |
||||
-- |
||||
-- timezones may vary based not only on location but the operating |
||||
-- system. the main correctness issue is that the OS may not get |
||||
-- daylight savings time right for times prior to Unix epoch (jan 1 1970). |
||||
-- |
||||
CREATE TABLE ABSTIME_TBL (f1 abstime); |
||||
BEGIN; |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now'); |
||||
SELECT count(*) AS two FROM ABSTIME_TBL WHERE f1 = 'now' ; |
||||
two |
||||
----- |
||||
2 |
||||
(1 row) |
||||
|
||||
END; |
||||
DELETE FROM ABSTIME_TBL; |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jan 14, 1973 03:14:21'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'Mon May 1 00:30:30 1995'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'epoch'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'infinity'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime '-infinity'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12'); |
||||
-- what happens if we specify slightly misformatted abstime? |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00'); |
||||
ERROR: date/time field value out of range: "Feb 35, 1946 10:00:00" |
||||
LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00'... |
||||
^ |
||||
HINT: Perhaps you need a different "datestyle" setting. |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10'); |
||||
ERROR: date/time field value out of range: "Feb 28, 1984 25:08:10" |
||||
LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10'... |
||||
^ |
||||
-- badly formatted abstimes: these should result in invalid abstimes |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format'); |
||||
ERROR: invalid input syntax for type abstime: "bad date format" |
||||
LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format'); |
||||
^ |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843'); |
||||
-- test abstime operators |
||||
SELECT '' AS eight, * FROM ABSTIME_TBL; |
||||
eight | f1 |
||||
-------+------------------------------ |
||||
| Sun Jan 14 03:14:21 1973 PST |
||||
| Mon May 01 00:30:30 1995 PDT |
||||
| Wed Dec 31 16:00:00 1969 PST |
||||
| infinity |
||||
| -infinity |
||||
| Sat May 10 23:59:12 1947 PST |
||||
| invalid |
||||
(7 rows) |
||||
|
||||
SELECT '' AS six, * FROM ABSTIME_TBL |
||||
WHERE ABSTIME_TBL.f1 < abstime 'Jun 30, 2001'; |
||||
six | f1 |
||||
-----+------------------------------ |
||||
| Sun Jan 14 03:14:21 1973 PST |
||||
| Mon May 01 00:30:30 1995 PDT |
||||
| Wed Dec 31 16:00:00 1969 PST |
||||
| -infinity |
||||
| Sat May 10 23:59:12 1947 PST |
||||
(5 rows) |
||||
|
||||
SELECT '' AS six, * FROM ABSTIME_TBL |
||||
WHERE ABSTIME_TBL.f1 > abstime '-infinity'; |
||||
six | f1 |
||||
-----+------------------------------ |
||||
| Sun Jan 14 03:14:21 1973 PST |
||||
| Mon May 01 00:30:30 1995 PDT |
||||
| Wed Dec 31 16:00:00 1969 PST |
||||
| infinity |
||||
| Sat May 10 23:59:12 1947 PST |
||||
| invalid |
||||
(6 rows) |
||||
|
||||
SELECT '' AS six, * FROM ABSTIME_TBL |
||||
WHERE abstime 'May 10, 1947 23:59:12' <> ABSTIME_TBL.f1; |
||||
six | f1 |
||||
-----+------------------------------ |
||||
| Sun Jan 14 03:14:21 1973 PST |
||||
| Mon May 01 00:30:30 1995 PDT |
||||
| Wed Dec 31 16:00:00 1969 PST |
||||
| infinity |
||||
| -infinity |
||||
| invalid |
||||
(6 rows) |
||||
|
||||
SELECT '' AS three, * FROM ABSTIME_TBL |
||||
WHERE abstime 'epoch' >= ABSTIME_TBL.f1; |
||||
three | f1 |
||||
-------+------------------------------ |
||||
| Wed Dec 31 16:00:00 1969 PST |
||||
| -infinity |
||||
| Sat May 10 23:59:12 1947 PST |
||||
(3 rows) |
||||
|
||||
SELECT '' AS four, * FROM ABSTIME_TBL |
||||
WHERE ABSTIME_TBL.f1 <= abstime 'Jan 14, 1973 03:14:21'; |
||||
four | f1 |
||||
------+------------------------------ |
||||
| Sun Jan 14 03:14:21 1973 PST |
||||
| Wed Dec 31 16:00:00 1969 PST |
||||
| -infinity |
||||
| Sat May 10 23:59:12 1947 PST |
||||
(4 rows) |
||||
|
||||
SELECT '' AS four, * FROM ABSTIME_TBL |
||||
WHERE ABSTIME_TBL.f1 <?> |
||||
tinterval '["Apr 1 1950 00:00:00" "Dec 30 1999 23:00:00"]'; |
||||
four | f1 |
||||
------+------------------------------ |
||||
| Sun Jan 14 03:14:21 1973 PST |
||||
| Mon May 01 00:30:30 1995 PDT |
||||
| Wed Dec 31 16:00:00 1969 PST |
||||
(3 rows) |
||||
|
||||
SELECT '' AS four, f1 AS abstime, |
||||
date_part('year', f1) AS year, date_part('month', f1) AS month, |
||||
date_part('day',f1) AS day, date_part('hour', f1) AS hour, |
||||
date_part('minute', f1) AS minute, date_part('second', f1) AS second |
||||
FROM ABSTIME_TBL |
||||
WHERE isfinite(f1) |
||||
ORDER BY abstime; |
||||
four | abstime | year | month | day | hour | minute | second |
||||
------+------------------------------+------+-------+-----+------+--------+-------- |
||||
| Sat May 10 23:59:12 1947 PST | 1947 | 5 | 10 | 23 | 59 | 12 |
||||
| Wed Dec 31 16:00:00 1969 PST | 1969 | 12 | 31 | 16 | 0 | 0 |
||||
| Sun Jan 14 03:14:21 1973 PST | 1973 | 1 | 14 | 3 | 14 | 21 |
||||
| Mon May 01 00:30:30 1995 PDT | 1995 | 5 | 1 | 0 | 30 | 30 |
||||
(4 rows) |
||||
|
@ -1,109 +0,0 @@ |
||||
-- |
||||
-- RELTIME |
||||
-- |
||||
CREATE TABLE RELTIME_TBL (f1 reltime); |
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 1 minute'); |
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 5 hour'); |
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 10 day'); |
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 34 year'); |
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 3 months'); |
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 14 seconds ago'); |
||||
-- badly formatted reltimes |
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('badly formatted reltime'); |
||||
ERROR: invalid input syntax for type reltime: "badly formatted reltime" |
||||
LINE 1: INSERT INTO RELTIME_TBL (f1) VALUES ('badly formatted reltim... |
||||
^ |
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 30 eons ago'); |
||||
ERROR: invalid input syntax for type reltime: "@ 30 eons ago" |
||||
LINE 1: INSERT INTO RELTIME_TBL (f1) VALUES ('@ 30 eons ago'); |
||||
^ |
||||
-- test reltime operators |
||||
SELECT '' AS six, * FROM RELTIME_TBL; |
||||
six | f1 |
||||
-----+--------------- |
||||
| @ 1 min |
||||
| @ 5 hours |
||||
| @ 10 days |
||||
| @ 34 years |
||||
| @ 3 mons |
||||
| @ 14 secs ago |
||||
(6 rows) |
||||
|
||||
SELECT '' AS five, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 <> reltime '@ 10 days'; |
||||
five | f1 |
||||
------+--------------- |
||||
| @ 1 min |
||||
| @ 5 hours |
||||
| @ 34 years |
||||
| @ 3 mons |
||||
| @ 14 secs ago |
||||
(5 rows) |
||||
|
||||
SELECT '' AS three, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 <= reltime '@ 5 hours'; |
||||
three | f1 |
||||
-------+--------------- |
||||
| @ 1 min |
||||
| @ 5 hours |
||||
| @ 14 secs ago |
||||
(3 rows) |
||||
|
||||
SELECT '' AS three, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 < reltime '@ 1 day'; |
||||
three | f1 |
||||
-------+--------------- |
||||
| @ 1 min |
||||
| @ 5 hours |
||||
| @ 14 secs ago |
||||
(3 rows) |
||||
|
||||
SELECT '' AS one, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 = reltime '@ 34 years'; |
||||
one | f1 |
||||
-----+------------ |
||||
| @ 34 years |
||||
(1 row) |
||||
|
||||
SELECT '' AS two, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 >= reltime '@ 1 month'; |
||||
two | f1 |
||||
-----+------------ |
||||
| @ 34 years |
||||
| @ 3 mons |
||||
(2 rows) |
||||
|
||||
SELECT '' AS five, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 > reltime '@ 3 seconds ago'; |
||||
five | f1 |
||||
------+------------ |
||||
| @ 1 min |
||||
| @ 5 hours |
||||
| @ 10 days |
||||
| @ 34 years |
||||
| @ 3 mons |
||||
(5 rows) |
||||
|
||||
SELECT '' AS fifteen, r1.*, r2.* |
||||
FROM RELTIME_TBL r1, RELTIME_TBL r2 |
||||
WHERE r1.f1 > r2.f1 |
||||
ORDER BY r1.f1, r2.f1; |
||||
fifteen | f1 | f1 |
||||
---------+------------+--------------- |
||||
| @ 1 min | @ 14 secs ago |
||||
| @ 5 hours | @ 14 secs ago |
||||
| @ 5 hours | @ 1 min |
||||
| @ 10 days | @ 14 secs ago |
||||
| @ 10 days | @ 1 min |
||||
| @ 10 days | @ 5 hours |
||||
| @ 3 mons | @ 14 secs ago |
||||
| @ 3 mons | @ 1 min |
||||
| @ 3 mons | @ 5 hours |
||||
| @ 3 mons | @ 10 days |
||||
| @ 34 years | @ 14 secs ago |
||||
| @ 34 years | @ 1 min |
||||
| @ 34 years | @ 5 hours |
||||
| @ 34 years | @ 10 days |
||||
| @ 34 years | @ 3 mons |
||||
(15 rows) |
||||
|
@ -1,172 +0,0 @@ |
||||
-- |
||||
-- TINTERVAL |
||||
-- |
||||
CREATE TABLE TINTERVAL_TBL (f1 tinterval); |
||||
-- Should accept any abstime, |
||||
-- so do not bother with extensive testing of values |
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["-infinity" "infinity"]'); |
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["May 10, 1947 23:59:12" "Jan 14, 1973 03:14:21"]'); |
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["Sep 4, 1983 23:59:12" "Oct 4, 1983 23:59:12"]'); |
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["epoch" "Mon May 1 00:30:30 1995"]'); |
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["Feb 15 1990 12:15:03" "2001-09-23 11:12:13"]'); |
||||
-- badly formatted tintervals |
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["bad time specifications" ""]'); |
||||
ERROR: invalid input syntax for type abstime: "bad time specifications" |
||||
LINE 2: VALUES ('["bad time specifications" ""]'); |
||||
^ |
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["" "infinity"]'); |
||||
ERROR: invalid input syntax for type abstime: "" |
||||
LINE 2: VALUES ('["" "infinity"]'); |
||||
^ |
||||
-- test tinterval operators |
||||
SELECT '' AS five, * FROM TINTERVAL_TBL; |
||||
five | f1 |
||||
------+----------------------------------------------------------------- |
||||
| ["-infinity" "infinity"] |
||||
| ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] |
||||
| ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
| ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] |
||||
(5 rows) |
||||
|
||||
-- length == |
||||
SELECT '' AS one, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #= '@ 1 months'; |
||||
one | f1 |
||||
-----+----------------------------------------------------------------- |
||||
| ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] |
||||
(1 row) |
||||
|
||||
-- length <> |
||||
SELECT '' AS three, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #<> '@ 1 months'; |
||||
three | f1 |
||||
-------+----------------------------------------------------------------- |
||||
| ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
| ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] |
||||
(3 rows) |
||||
|
||||
-- length < |
||||
SELECT '' AS zero, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #< '@ 1 month'; |
||||
zero | f1 |
||||
------+---- |
||||
(0 rows) |
||||
|
||||
-- length <= |
||||
SELECT '' AS one, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #<= '@ 1 month'; |
||||
one | f1 |
||||
-----+----------------------------------------------------------------- |
||||
| ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] |
||||
(1 row) |
||||
|
||||
-- length > |
||||
SELECT '' AS three, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #> '@ 1 year'; |
||||
three | f1 |
||||
-------+----------------------------------------------------------------- |
||||
| ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
| ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] |
||||
(3 rows) |
||||
|
||||
-- length >= |
||||
SELECT '' AS three, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #>= '@ 3 years'; |
||||
three | f1 |
||||
-------+----------------------------------------------------------------- |
||||
| ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
| ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] |
||||
(3 rows) |
||||
|
||||
-- overlaps |
||||
SELECT '' AS three, t1.* |
||||
FROM TINTERVAL_TBL t1 |
||||
WHERE t1.f1 && |
||||
tinterval '["Aug 15 14:23:19 1983" "Sep 16 14:23:19 1983"]'; |
||||
three | f1 |
||||
-------+----------------------------------------------------------------- |
||||
| ["-infinity" "infinity"] |
||||
| ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
(3 rows) |
||||
|
||||
SELECT '' AS five, t1.f1, t2.f1 |
||||
FROM TINTERVAL_TBL t1, TINTERVAL_TBL t2 |
||||
WHERE t1.f1 && t2.f1 and |
||||
t1.f1 = t2.f1 |
||||
ORDER BY t1.f1, t2.f1; |
||||
five | f1 | f1 |
||||
------+-----------------------------------------------------------------+----------------------------------------------------------------- |
||||
| ["-infinity" "infinity"] | ["-infinity" "infinity"] |
||||
| ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] | ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] |
||||
| ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] | ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] | ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
| ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] | ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] |
||||
(5 rows) |
||||
|
||||
SELECT '' AS fourteen, t1.f1 AS interval1, t2.f1 AS interval2 |
||||
FROM TINTERVAL_TBL t1, TINTERVAL_TBL t2 |
||||
WHERE t1.f1 && t2.f1 and not t1.f1 = t2.f1 |
||||
ORDER BY interval1, interval2; |
||||
fourteen | interval1 | interval2 |
||||
----------+-----------------------------------------------------------------+----------------------------------------------------------------- |
||||
| ["-infinity" "infinity"] | ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] |
||||
| ["-infinity" "infinity"] | ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] |
||||
| ["-infinity" "infinity"] | ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
| ["-infinity" "infinity"] | ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] |
||||
| ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] | ["-infinity" "infinity"] |
||||
| ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] | ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
| ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] | ["-infinity" "infinity"] |
||||
| ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] | ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] | ["-infinity" "infinity"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] | ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] | ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] | ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] |
||||
| ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] | ["-infinity" "infinity"] |
||||
| ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] | ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
(14 rows) |
||||
|
||||
-- contains |
||||
SELECT '' AS five, t1.f1 |
||||
FROM TINTERVAL_TBL t1 |
||||
WHERE not t1.f1 << |
||||
tinterval '["Aug 15 14:23:19 1980" "Sep 16 14:23:19 1990"]' |
||||
ORDER BY t1.f1; |
||||
five | f1 |
||||
------+----------------------------------------------------------------- |
||||
| ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] |
||||
| ["Thu Feb 15 12:15:03 1990 PST" "Sun Sep 23 11:12:13 2001 PDT"] |
||||
| ["Sat May 10 23:59:12 1947 PST" "Sun Jan 14 03:14:21 1973 PST"] |
||||
(3 rows) |
||||
|
||||
-- make time interval |
||||
SELECT '' AS three, t1.f1 |
||||
FROM TINTERVAL_TBL t1 |
||||
WHERE t1.f1 && |
||||
(abstime 'Aug 15 14:23:19 1983' <#> |
||||
abstime 'Sep 16 14:23:19 1983') |
||||
ORDER BY t1.f1; |
||||
three | f1 |
||||
-------+----------------------------------------------------------------- |
||||
| ["-infinity" "infinity"] |
||||
| ["Sun Sep 04 23:59:12 1983 PDT" "Tue Oct 04 23:59:12 1983 PDT"] |
||||
| ["Wed Dec 31 16:00:00 1969 PST" "Mon May 01 00:30:30 1995 PDT"] |
||||
(3 rows) |
||||
|
@ -1,67 +0,0 @@ |
||||
-- |
||||
-- ABSTIME |
||||
-- testing built-in time type abstime |
||||
-- uses reltime and tinterval |
||||
-- |
||||
|
||||
-- |
||||
-- timezones may vary based not only on location but the operating |
||||
-- system. the main correctness issue is that the OS may not get |
||||
-- daylight savings time right for times prior to Unix epoch (jan 1 1970). |
||||
-- |
||||
|
||||
CREATE TABLE ABSTIME_TBL (f1 abstime); |
||||
|
||||
BEGIN; |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now'); |
||||
SELECT count(*) AS two FROM ABSTIME_TBL WHERE f1 = 'now' ; |
||||
END; |
||||
|
||||
DELETE FROM ABSTIME_TBL; |
||||
|
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jan 14, 1973 03:14:21'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'Mon May 1 00:30:30 1995'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'epoch'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'infinity'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime '-infinity'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12'); |
||||
|
||||
-- what happens if we specify slightly misformatted abstime? |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10'); |
||||
|
||||
-- badly formatted abstimes: these should result in invalid abstimes |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format'); |
||||
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843'); |
||||
|
||||
-- test abstime operators |
||||
|
||||
SELECT '' AS eight, * FROM ABSTIME_TBL; |
||||
|
||||
SELECT '' AS six, * FROM ABSTIME_TBL |
||||
WHERE ABSTIME_TBL.f1 < abstime 'Jun 30, 2001'; |
||||
|
||||
SELECT '' AS six, * FROM ABSTIME_TBL |
||||
WHERE ABSTIME_TBL.f1 > abstime '-infinity'; |
||||
|
||||
SELECT '' AS six, * FROM ABSTIME_TBL |
||||
WHERE abstime 'May 10, 1947 23:59:12' <> ABSTIME_TBL.f1; |
||||
|
||||
SELECT '' AS three, * FROM ABSTIME_TBL |
||||
WHERE abstime 'epoch' >= ABSTIME_TBL.f1; |
||||
|
||||
SELECT '' AS four, * FROM ABSTIME_TBL |
||||
WHERE ABSTIME_TBL.f1 <= abstime 'Jan 14, 1973 03:14:21'; |
||||
|
||||
SELECT '' AS four, * FROM ABSTIME_TBL |
||||
WHERE ABSTIME_TBL.f1 <?> |
||||
tinterval '["Apr 1 1950 00:00:00" "Dec 30 1999 23:00:00"]'; |
||||
|
||||
SELECT '' AS four, f1 AS abstime, |
||||
date_part('year', f1) AS year, date_part('month', f1) AS month, |
||||
date_part('day',f1) AS day, date_part('hour', f1) AS hour, |
||||
date_part('minute', f1) AS minute, date_part('second', f1) AS second |
||||
FROM ABSTIME_TBL |
||||
WHERE isfinite(f1) |
||||
ORDER BY abstime; |
@ -1,50 +0,0 @@ |
||||
-- |
||||
-- RELTIME |
||||
-- |
||||
|
||||
CREATE TABLE RELTIME_TBL (f1 reltime); |
||||
|
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 1 minute'); |
||||
|
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 5 hour'); |
||||
|
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 10 day'); |
||||
|
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 34 year'); |
||||
|
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 3 months'); |
||||
|
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 14 seconds ago'); |
||||
|
||||
|
||||
-- badly formatted reltimes |
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('badly formatted reltime'); |
||||
|
||||
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 30 eons ago'); |
||||
|
||||
-- test reltime operators |
||||
|
||||
SELECT '' AS six, * FROM RELTIME_TBL; |
||||
|
||||
SELECT '' AS five, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 <> reltime '@ 10 days'; |
||||
|
||||
SELECT '' AS three, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 <= reltime '@ 5 hours'; |
||||
|
||||
SELECT '' AS three, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 < reltime '@ 1 day'; |
||||
|
||||
SELECT '' AS one, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 = reltime '@ 34 years'; |
||||
|
||||
SELECT '' AS two, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 >= reltime '@ 1 month'; |
||||
|
||||
SELECT '' AS five, * FROM RELTIME_TBL |
||||
WHERE RELTIME_TBL.f1 > reltime '@ 3 seconds ago'; |
||||
|
||||
SELECT '' AS fifteen, r1.*, r2.* |
||||
FROM RELTIME_TBL r1, RELTIME_TBL r2 |
||||
WHERE r1.f1 > r2.f1 |
||||
ORDER BY r1.f1, r2.f1; |
@ -1,97 +0,0 @@ |
||||
-- |
||||
-- TINTERVAL |
||||
-- |
||||
|
||||
CREATE TABLE TINTERVAL_TBL (f1 tinterval); |
||||
|
||||
-- Should accept any abstime, |
||||
-- so do not bother with extensive testing of values |
||||
|
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["-infinity" "infinity"]'); |
||||
|
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["May 10, 1947 23:59:12" "Jan 14, 1973 03:14:21"]'); |
||||
|
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["Sep 4, 1983 23:59:12" "Oct 4, 1983 23:59:12"]'); |
||||
|
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["epoch" "Mon May 1 00:30:30 1995"]'); |
||||
|
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["Feb 15 1990 12:15:03" "2001-09-23 11:12:13"]'); |
||||
|
||||
|
||||
-- badly formatted tintervals |
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["bad time specifications" ""]'); |
||||
|
||||
INSERT INTO TINTERVAL_TBL (f1) |
||||
VALUES ('["" "infinity"]'); |
||||
|
||||
-- test tinterval operators |
||||
|
||||
SELECT '' AS five, * FROM TINTERVAL_TBL; |
||||
|
||||
-- length == |
||||
SELECT '' AS one, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #= '@ 1 months'; |
||||
|
||||
-- length <> |
||||
SELECT '' AS three, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #<> '@ 1 months'; |
||||
|
||||
-- length < |
||||
SELECT '' AS zero, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #< '@ 1 month'; |
||||
|
||||
-- length <= |
||||
SELECT '' AS one, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #<= '@ 1 month'; |
||||
|
||||
-- length > |
||||
SELECT '' AS three, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #> '@ 1 year'; |
||||
|
||||
-- length >= |
||||
SELECT '' AS three, t.* |
||||
FROM TINTERVAL_TBL t |
||||
WHERE t.f1 #>= '@ 3 years'; |
||||
|
||||
-- overlaps |
||||
SELECT '' AS three, t1.* |
||||
FROM TINTERVAL_TBL t1 |
||||
WHERE t1.f1 && |
||||
tinterval '["Aug 15 14:23:19 1983" "Sep 16 14:23:19 1983"]'; |
||||
|
||||
SELECT '' AS five, t1.f1, t2.f1 |
||||
FROM TINTERVAL_TBL t1, TINTERVAL_TBL t2 |
||||
WHERE t1.f1 && t2.f1 and |
||||
t1.f1 = t2.f1 |
||||
ORDER BY t1.f1, t2.f1; |
||||
|
||||
SELECT '' AS fourteen, t1.f1 AS interval1, t2.f1 AS interval2 |
||||
FROM TINTERVAL_TBL t1, TINTERVAL_TBL t2 |
||||
WHERE t1.f1 && t2.f1 and not t1.f1 = t2.f1 |
||||
ORDER BY interval1, interval2; |
||||
|
||||
-- contains |
||||
SELECT '' AS five, t1.f1 |
||||
FROM TINTERVAL_TBL t1 |
||||
WHERE not t1.f1 << |
||||
tinterval '["Aug 15 14:23:19 1980" "Sep 16 14:23:19 1990"]' |
||||
ORDER BY t1.f1; |
||||
|
||||
-- make time interval |
||||
SELECT '' AS three, t1.f1 |
||||
FROM TINTERVAL_TBL t1 |
||||
WHERE t1.f1 && |
||||
(abstime 'Aug 15 14:23:19 1983' <#> |
||||
abstime 'Sep 16 14:23:19 1983') |
||||
ORDER BY t1.f1; |
Loading…
Reference in new issue