|
||||
0001 -- 0002 -- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group 0003 -- 0004 -- 0005 -- INTERVAL 0006 -- https://github.com/postgres/postgres/blob/REL_12_STABLE/src/test/regress/sql/interval.sql 0007 0008 -- [SPARK-28259] Date/Time Output Styles and Date Order Conventions 0009 -- SET DATESTYLE = 'ISO'; 0010 -- [SPARK-29406] Interval output styles 0011 -- SET IntervalStyle to postgres; 0012 0013 -- check acceptance of "time zone style" 0014 -- [SPARK-29369] Accept strings without `interval` prefix in casting to intervals 0015 -- [SPARK-29370] Interval strings without explicit unit markings 0016 -- SELECT INTERVAL '01:00' AS `One hour`; 0017 -- SELECT INTERVAL '+02:00' AS `Two hours`; 0018 -- SELECT INTERVAL '-08:00' AS `Eight hours`; 0019 -- SELECT INTERVAL '-1 +02:03' AS `22 hours ago...`; 0020 -- SELECT INTERVAL '-1 days +02:03' AS `22 hours ago...`; 0021 -- [SPARK-29371] Support interval field values with fractional parts 0022 -- SELECT INTERVAL '1.5 weeks' AS `Ten days twelve hours`; 0023 -- SELECT INTERVAL '1.5 months' AS `One month 15 days`; 0024 -- SELECT INTERVAL '10 years -11 month -12 days +13:14' AS `9 years...`; 0025 0026 -- [SPARK-29382] Support writing `INTERVAL` type to datasource table 0027 -- CREATE TABLE INTERVAL_TBL (f1 interval); 0028 0029 -- [SPARK-29383] Support the optional prefix `@` in interval strings 0030 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 1 minute'); 0031 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 5 hour'); 0032 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 10 day'); 0033 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 34 year'); 0034 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 3 months'); 0035 -- [SPARK-29384] Support `ago` in interval strings 0036 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 14 seconds ago'); 0037 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('1 day 2 hours 3 minutes 4 seconds'); 0038 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('6 years'); 0039 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months'); 0040 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours'); 0041 0042 -- badly formatted interval 0043 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval'); 0044 -- INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago'); 0045 0046 -- test interval operators 0047 0048 -- SELECT '' AS ten, * FROM INTERVAL_TBL; 0049 -- [SPARK-29385] Make `INTERVAL` values comparable 0050 -- SELECT '' AS nine, * FROM INTERVAL_TBL 0051 -- WHERE INTERVAL_TBL.f1 <> interval '@ 10 days'; 0052 0053 -- SELECT '' AS three, * FROM INTERVAL_TBL 0054 -- WHERE INTERVAL_TBL.f1 <= interval '@ 5 hours'; 0055 0056 -- SELECT '' AS three, * FROM INTERVAL_TBL 0057 -- WHERE INTERVAL_TBL.f1 < interval '@ 1 day'; 0058 0059 -- SELECT '' AS one, * FROM INTERVAL_TBL 0060 -- WHERE INTERVAL_TBL.f1 = interval '@ 34 years'; 0061 0062 -- SELECT '' AS five, * FROM INTERVAL_TBL 0063 -- WHERE INTERVAL_TBL.f1 >= interval '@ 1 month'; 0064 0065 -- SELECT '' AS nine, * FROM INTERVAL_TBL 0066 -- WHERE INTERVAL_TBL.f1 > interval '@ 3 seconds ago'; 0067 0068 -- SELECT '' AS fortyfive, r1.*, r2.* 0069 -- FROM INTERVAL_TBL r1, INTERVAL_TBL r2 0070 -- WHERE r1.f1 > r2.f1 0071 -- ORDER BY r1.f1, r2.f1; 0072 0073 -- Test intervals that are large enough to overflow 64 bits in comparisons 0074 -- [SPARK-29369] Accept strings without `interval` prefix in casting to intervals 0075 -- CREATE TEMP TABLE INTERVAL_TBL_OF (f1 interval); 0076 -- INSERT INTO INTERVAL_TBL_OF (f1) VALUES 0077 -- ('2147483647 days 2147483647 months'), 0078 -- ('2147483647 days -2147483648 months'), 0079 -- ('1 year'), 0080 -- ('-2147483648 days 2147483647 months'), 0081 -- ('-2147483648 days -2147483648 months'); 0082 -- these should fail as out-of-range 0083 -- INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483648 days'); 0084 -- INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483649 days'); 0085 -- INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483647 years'); 0086 -- INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years'); 0087 0088 -- SELECT r1.*, r2.* 0089 -- FROM INTERVAL_TBL_OF r1, INTERVAL_TBL_OF r2 0090 -- WHERE r1.f1 > r2.f1 0091 -- ORDER BY r1.f1, r2.f1; 0092 0093 -- CREATE INDEX ON INTERVAL_TBL_OF USING btree (f1); 0094 -- SET enable_seqscan TO false; 0095 -- EXPLAIN (COSTS OFF) 0096 -- SELECT f1 FROM INTERVAL_TBL_OF r1 ORDER BY f1; 0097 -- SELECT f1 FROM INTERVAL_TBL_OF r1 ORDER BY f1; 0098 -- RESET enable_seqscan; 0099 0100 -- DROP TABLE INTERVAL_TBL_OF; 0101 0102 -- Test multiplication and division with intervals. 0103 -- Floating point arithmetic rounding errors can lead to unexpected results, 0104 -- though the code attempts to do the right thing and round up to days and 0105 -- minutes to avoid results such as '3 days 24:00 hours' or '14:20:60'. 0106 -- Note that it is expected for some day components to be greater than 29 and 0107 -- some time components be greater than 23:59:59 due to how intervals are 0108 -- stored internally. 0109 -- [SPARK-29386] Copy data between a file and a table 0110 -- CREATE TABLE INTERVAL_MULDIV_TBL (span interval); 0111 -- COPY INTERVAL_MULDIV_TBL FROM STDIN; 0112 -- 41 mon 12 days 360:00 0113 -- -41 mon -12 days +360:00 0114 -- -12 days 0115 -- 9 mon -27 days 12:34:56 0116 -- -3 years 482 days 76:54:32.189 0117 -- 4 mon 0118 -- 14 mon 0119 -- 999 mon 999 days 0120 -- \. 0121 -- [SPARK-29387] Support `*` and `\` operators for intervals 0122 -- SELECT span * 0.3 AS product 0123 -- FROM INTERVAL_MULDIV_TBL; 0124 0125 -- SELECT span * 8.2 AS product 0126 -- FROM INTERVAL_MULDIV_TBL; 0127 0128 -- SELECT span / 10 AS quotient 0129 -- FROM INTERVAL_MULDIV_TBL; 0130 0131 -- SELECT span / 100 AS quotient 0132 -- FROM INTERVAL_MULDIV_TBL; 0133 0134 -- DROP TABLE INTERVAL_MULDIV_TBL; 0135 -- [SPARK-28259] Date/Time Output Styles and Date Order Conventions 0136 -- SET DATESTYLE = 'postgres'; 0137 -- [SPARK-29406] Interval output styles 0138 -- SET IntervalStyle to postgres_verbose; 0139 0140 -- SELECT '' AS ten, * FROM INTERVAL_TBL; 0141 0142 -- test avg(interval), which is somewhat fragile since people have been 0143 -- known to change the allowed input syntax for type interval without 0144 -- updating pg_aggregate.agginitval 0145 0146 -- select avg(f1) from interval_tbl; 0147 0148 -- test long interval input 0149 -- [SPARK-29388] Construct intervals from the `millenniums`, `centuries` or `decades` units 0150 -- select '4 millenniums 5 centuries 4 decades 1 year 4 months 4 days 17 minutes 31 seconds'::interval; 0151 0152 -- test long interval output 0153 -- Note: the actual maximum length of the interval output is longer, 0154 -- but we need the test to work for both integer and floating-point 0155 -- timestamps. 0156 -- [SPARK-29389] Support synonyms for interval units 0157 -- select '100000000y 10mon -1000000000d -100000h -10min -10.000001s ago'::interval; 0158 0159 -- test justify_hours() and justify_days() 0160 -- [SPARK-29390] Add the justify_days(), justify_hours() and justify_interval() functions 0161 -- SELECT justify_hours(interval '6 months 3 days 52 hours 3 minutes 2 seconds') as `6 mons 5 days 4 hours 3 mins 2 seconds`; 0162 -- SELECT justify_days(interval '6 months 36 days 5 hours 4 minutes 3 seconds') as `7 mons 6 days 5 hours 4 mins 3 seconds`; 0163 0164 -- test justify_interval() 0165 0166 -- SELECT justify_interval(interval '1 month -1 hour') as `1 month -1 hour`; 0167 0168 -- test fractional second input, and detection of duplicate units 0169 -- [SPARK-28259] Date/Time Output Styles and Date Order Conventions 0170 -- SET DATESTYLE = 'ISO'; 0171 -- [SPARK-29406] Interval output styles 0172 -- SET IntervalStyle TO postgres; 0173 -- [SPARK-29369] Accept strings without `interval` prefix in casting to intervals 0174 -- SELECT '1 millisecond'::interval, '1 microsecond'::interval, 0175 -- '500 seconds 99 milliseconds 51 microseconds'::interval; 0176 -- SELECT '3 days 5 milliseconds'::interval; 0177 0178 -- SELECT '1 second 2 seconds'::interval; -- error 0179 -- SELECT '10 milliseconds 20 milliseconds'::interval; -- error 0180 -- SELECT '5.5 seconds 3 milliseconds'::interval; -- error 0181 -- SELECT '1:20:05 5 microseconds'::interval; -- error 0182 -- SELECT '1 day 1 day'::interval; -- error 0183 -- [SPARK-29391] Default year-month units 0184 -- SELECT interval '1-2'; -- SQL year-month literal 0185 SELECT interval '999' second; -- oversize leading field is ok 0186 SELECT interval '999' minute; 0187 SELECT interval '999' hour; 0188 SELECT interval '999' day; 0189 SELECT interval '999' month; 0190 0191 -- test SQL-spec syntaxes for restricted field sets 0192 SELECT interval '1' year; 0193 SELECT interval '2' month; 0194 SELECT interval '3' day; 0195 SELECT interval '4' hour; 0196 SELECT interval '5' minute; 0197 SELECT interval '6' second; 0198 -- [SPARK-29391] Default year-month units 0199 -- SELECT interval '1' year to month; 0200 SELECT interval '1-2' year to month; 0201 -- [SPARK-29391] Default year-month units 0202 -- SELECT interval '1 2' day to hour; 0203 SELECT interval '1 2:03' day to hour; 0204 SELECT interval '1 2:03:04' day to hour; 0205 -- SELECT interval '1 2' day to minute; 0206 SELECT interval '1 2:03' day to minute; 0207 SELECT interval '1 2:03:04' day to minute; 0208 -- SELECT interval '1 2' day to second; 0209 SELECT interval '1 2:03' day to second; 0210 SELECT interval '1 2:03:04' day to second; 0211 -- SELECT interval '1 2' hour to minute; 0212 SELECT interval '1 2:03' hour to minute; 0213 SELECT interval '1 2:03:04' hour to minute; 0214 -- SELECT interval '1 2' hour to second; 0215 SELECT interval '1 2:03' hour to second; 0216 SELECT interval '1 2:03:04' hour to second; 0217 -- SELECT interval '1 2' minute to second; 0218 SELECT interval '1 2:03' minute to second; 0219 SELECT interval '1 2:03:04' minute to second; 0220 -- [SPARK-29370] Interval strings without explicit unit markings 0221 -- SELECT interval '1 +2:03' minute to second; 0222 -- SELECT interval '1 +2:03:04' minute to second; 0223 -- SELECT interval '1 -2:03' minute to second; 0224 -- SELECT interval '1 -2:03:04' minute to second; 0225 -- SELECT interval '123 11' day to hour; -- ok 0226 -- SELECT interval '123 11' day; -- not ok 0227 -- SELECT interval '123 11'; -- not ok, too ambiguous 0228 -- SELECT interval '123 2:03 -2:04'; -- not ok, redundant hh:mm fields 0229 0230 -- test syntaxes for restricted precision 0231 -- [SPARK-29395] Precision of the interval type 0232 -- SELECT interval(0) '1 day 01:23:45.6789'; 0233 -- SELECT interval(2) '1 day 01:23:45.6789'; 0234 -- SELECT interval '12:34.5678' minute to second(2); -- per SQL spec 0235 -- SELECT interval '1.234' second; 0236 -- SELECT interval '1.234' second(2); 0237 -- SELECT interval '1 2.345' day to second(2); 0238 -- SELECT interval '1 2:03' day to second(2); 0239 -- SELECT interval '1 2:03.4567' day to second(2); 0240 -- SELECT interval '1 2:03:04.5678' day to second(2); 0241 -- SELECT interval '1 2.345' hour to second(2); 0242 -- SELECT interval '1 2:03.45678' hour to second(2); 0243 -- SELECT interval '1 2:03:04.5678' hour to second(2); 0244 -- SELECT interval '1 2.3456' minute to second(2); 0245 -- SELECT interval '1 2:03.5678' minute to second(2); 0246 -- SELECT interval '1 2:03:04.5678' minute to second(2); 0247 0248 -- test casting to restricted precision (bug #14479) 0249 -- SELECT f1, f1::INTERVAL DAY TO MINUTE AS `minutes`, 0250 -- (f1 + INTERVAL '1 month')::INTERVAL MONTH::INTERVAL YEAR AS `years` 0251 -- FROM interval_tbl; 0252 0253 -- test inputting and outputting SQL standard interval literals 0254 -- [SPARK-29406] Interval output styles 0255 -- SET IntervalStyle TO sql_standard; 0256 -- [SPARK-29407] Support syntax for zero interval 0257 -- SELECT interval '0' AS zero, 0258 -- interval '1-2' year to month AS `year-month`, 0259 -- interval '1 2:03:04' day to second AS `day-time`, 0260 -- [SPARK-29408] Support interval literal with negative sign `-` 0261 -- - interval '1-2' AS `negative year-month`, 0262 -- - interval '1 2:03:04' AS `negative day-time`; 0263 0264 -- test input of some not-quite-standard interval values in the sql style 0265 -- [SPARK-29406] Interval output styles 0266 -- SET IntervalStyle TO postgres; 0267 -- SELECT interval '+1 -1:00:00', 0268 -- interval '-1 +1:00:00', 0269 -- interval '+1-2 -3 +4:05:06.789', 0270 -- interval '-1-2 +3 -4:05:06.789'; 0271 0272 -- test output of couple non-standard interval values in the sql style 0273 -- [SPARK-29406] Interval output styles 0274 -- SET IntervalStyle TO sql_standard; 0275 -- SELECT interval '1 day -1 hours', 0276 -- interval '-1 days +1 hours', 0277 -- interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds', 0278 -- - interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds'; 0279 0280 -- test outputting iso8601 intervals 0281 -- [SPARK-29406] Interval output styles 0282 -- SET IntervalStyle to iso_8601; 0283 -- select interval '0' AS zero, 0284 -- interval '1-2' AS `a year 2 months`, 0285 -- interval '1 2:03:04' AS `a bit over a day`, 0286 -- interval '2:03:04.45679' AS `a bit over 2 hours`, 0287 -- (interval '1-2' + interval '3 4:05:06.7') AS `all fields`, 0288 -- (interval '1-2' - interval '3 4:05:06.7') AS `mixed sign`, 0289 -- (- interval '1-2' + interval '3 4:05:06.7') AS negative; 0290 0291 -- test inputting ISO 8601 4.4.2.1 "Format With Time Unit Designators" 0292 -- [SPARK-29406] Interval output styles 0293 -- SET IntervalStyle to sql_standard; 0294 -- [SPARK-29394] Support ISO 8601 format for intervals 0295 -- select interval 'P0Y' AS zero, 0296 -- interval 'P1Y2M' AS `a year 2 months`, 0297 -- interval 'P1W' AS `a week`, 0298 -- interval 'P1DT2H3M4S' AS `a bit over a day`, 0299 -- interval 'P1Y2M3DT4H5M6.7S' AS `all fields`, 0300 -- interval 'P-1Y-2M-3DT-4H-5M-6.7S' AS negative, 0301 -- interval 'PT-0.1S' AS `fractional second`; 0302 0303 -- test inputting ISO 8601 4.4.2.2 "Alternative Format" 0304 -- [SPARK-29406] Interval output styles 0305 -- SET IntervalStyle to postgres; 0306 -- select interval 'P00021015T103020' AS `ISO8601 Basic Format`, 0307 -- interval 'P0002-10-15T10:30:20' AS `ISO8601 Extended Format`; 0308 0309 -- Make sure optional ISO8601 alternative format fields are optional. 0310 -- select interval 'P0002' AS `year only`, 0311 -- interval 'P0002-10' AS `year month`, 0312 -- interval 'P0002-10-15' AS `year month day`, 0313 -- interval 'P0002T1S' AS `year only plus time`, 0314 -- interval 'P0002-10T1S' AS `year month plus time`, 0315 -- interval 'P0002-10-15T1S' AS `year month day plus time`, 0316 -- interval 'PT10' AS `hour only`, 0317 -- interval 'PT10:30' AS `hour minute`; 0318 0319 -- test a couple rounding cases that changed since 8.3 w/ HAVE_INT64_TIMESTAMP. 0320 -- [SPARK-29406] Interval output styles 0321 -- SET IntervalStyle to postgres_verbose; 0322 -- select interval '-10 mons -3 days +03:55:06.70'; 0323 -- select interval '1 year 2 mons 3 days 04:05:06.699999'; 0324 -- select interval '0:0:0.7', interval '@ 0.70 secs', interval '0.7 seconds'; 0325 0326 -- check that '30 days' equals '1 month' according to the hash function 0327 -- [SPARK-29385] Make `INTERVAL` values comparable 0328 -- select '30 days'::interval = '1 month'::interval as t; 0329 -- select interval_hash('30 days'::interval) = interval_hash('1 month'::interval) as t; 0330 0331 -- numeric constructor 0332 -- [SPARK-29393] Add the make_interval() function 0333 -- select make_interval(years := 2); 0334 -- select make_interval(years := 1, months := 6); 0335 -- select make_interval(years := 1, months := -1, weeks := 5, days := -7, hours := 25, mins := -180); 0336 0337 -- select make_interval() = make_interval(years := 0, months := 0, weeks := 0, days := 0, mins := 0, secs := 0.0); 0338 -- select make_interval(hours := -2, mins := -10, secs := -25.3); 0339 0340 -- select make_interval(years := 'inf'::float::int); 0341 -- select make_interval(months := 'NaN'::float::int); 0342 -- select make_interval(secs := 'inf'); 0343 -- select make_interval(secs := 'NaN'); 0344 -- select make_interval(secs := 7e12);
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |