PostgreSQL Source Code: src/backend/utils/adt/timestamp.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18#include <ctype.h>
19#include <math.h>
20#include <limits.h>
22
42
43
44
45
46
47#ifdef __FAST_MATH__
48#error -ffast-math is known to break this code
49#endif
50
51
53
54
56
64
73
74
75
76
77
86
87#define IA_TOTAL_COUNT(ia) \
88 ((ia)->N + (ia)->pInfcount + (ia)->nInfcount)
89
93 Node *escontext);
96
99
100
103{
105 int n;
106
108
109
110
111
112
113 if (n != 1)
116 errmsg("invalid type modifier")));
117
119}
120
121
124{
125 if (typmod < 0)
128 errmsg("TIMESTAMP(%d)%s precision must not be negative",
129 typmod, (istz ? " WITH TIME ZONE" : ""))));
131 {
134 errmsg("TIMESTAMP(%d)%s precision reduced to maximum allowed, %d",
135 typmod, (istz ? " WITH TIME ZONE" : ""),
138 }
139
140 return typmod;
141}
142
143
144static char *
146{
147 const char *tz = istz ? " with time zone" : " without time zone";
148
149 if (typmod >= 0)
150 return psprintf("(%d)%s", (int) typmod, tz);
151 else
153}
154
155
156
157
158
159
160
161
162
165{
167#ifdef NOT_USED
169#endif
171 Node *escontext = fcinfo->context;
176 int tz;
177 int dtype;
178 int nf;
184
189 &dtype, tm, &fsec, &tz, &extra);
191 {
194 }
195
196 switch (dtype)
197 {
202 errmsg("timestamp out of range: \"%s\"", str)));
203 break;
204
207 break;
208
211 break;
212
215 break;
216
217 default:
218 elog(ERROR, "unexpected dtype %d while parsing timestamp \"%s\"",
219 dtype, str);
221 }
222
224
226}
227
228
229
230
233{
235 char *result;
240
245 else
248 errmsg("timestamp out of range")));
249
252}
253
254
255
256
259{
261
262#ifdef NOT_USED
264#endif
270
272
273
275 ;
280 errmsg("timestamp out of range")));
281
283
285}
286
287
288
289
300
308
316
317
318
319
320
321
322
323
326{
329
331 {
333
335 }
336
338}
339
340
341
342
343
357
358
359
360
361
362
363
364
365bool
367{
376 };
377
386 };
387
390 {
392 ereturn(escontext, false,
394 errmsg("timestamp(%d) precision must be between %d and %d",
396
398 {
401 }
402 else
403 {
406 }
407 }
408
409 return true;
410}
411
412
413
414
417{
419#ifdef NOT_USED
421#endif
423 Node *escontext = fcinfo->context;
428 int tz;
429 int dtype;
430 int nf;
436
441 &dtype, tm, &fsec, &tz, &extra);
443 {
445 escontext);
447 }
448
449 switch (dtype)
450 {
455 errmsg("timestamp out of range: \"%s\"", str)));
456 break;
457
460 break;
461
464 break;
465
468 break;
469
470 default:
471 elog(ERROR, "unexpected dtype %d while parsing timestamptz \"%s\"",
472 dtype, str);
474 }
475
477
479}
480
481
482
483
484
485
486
487
488static int
490{
493 int tz;
494
496
497
498
499
500
501
502
503
504
505
506
510 errmsg("invalid input syntax for type %s: \"%s\"",
511 "numeric time zone", tzname),
512 errhint("Numeric time zones must have \"-\" or \"+\" as first character.")));
513
516 {
520
524 errmsg("numeric time zone \"%s\" out of range", tzname)));
528 errmsg("time zone \"%s\" not recognized", tzname)));
529
531
533 {
534
535 tz = -val;
536 }
538 {
539
541 }
542 else
543 {
544
546 }
547 }
548
549 return tz;
550}
551
552
553
554
555
556
566
567
568
569
570
573 int hour, int min, double sec)
574{
579 bool bc = false;
581
585
586
588 {
589 bc = true;
591 }
592
594
598 errmsg("date field value out of range: %d-%02d-%02d",
599 year, month, day)));
600
604 errmsg("date out of range: %d-%02d-%02d",
605 year, month, day)));
606
608
609
613 errmsg("time field value out of range: %d:%02d:%02g",
614 hour, min, sec)));
615
616
619
624 errmsg("timestamp out of range: %d-%02d-%02d %d:%02d:%02g",
625 year, month, day,
626 hour, min, sec)));
627
628
632 errmsg("timestamp out of range: %d-%02d-%02d %d:%02d:%02g",
633 year, month, day,
634 hour, min, sec)));
635
636 return result;
637}
638
639
640
641
644{
652
654 hour, min, sec);
655
657}
658
659
660
661
664{
672
674 hour, min, sec);
675
677}
678
679
680
681
682
685{
696 int tz;
698
700 hour, min, sec);
701
705 errmsg("timestamp out of range")));
706
708
710
714 errmsg("timestamp out of range")));
715
717}
718
719
720
721
722
725{
728
729
733 errmsg("timestamp cannot be NaN")));
734
736 {
739 else
741 }
742 else
743 {
744
751 errmsg("timestamp out of range: \"%g\"", seconds)));
752
753
755
758
759
763 errmsg("timestamp out of range: \"%g\"",
765 }
766
768}
769
770
771
772
775{
777 char *result;
778 int tz;
782 const char *tzn;
784
789 else
792 errmsg("timestamp out of range")));
793
796}
797
798
799
800
803{
805
806#ifdef NOT_USED
808#endif
811 int tz;
815
817
818
820 ;
825 errmsg("timestamp out of range")));
826
828
830}
831
832
833
834
845
853
861
862
863
864
865
866
880
881
882
883
884
885
886
887
890{
892#ifdef NOT_USED
894#endif
896 Node *escontext = fcinfo->context;
900 int dtype;
901 int nf;
908
913
914 if (typmod >= 0)
916 else
918
924
925
929
931 {
936 }
937
939
940 switch (dtype)
941 {
946 errmsg("interval out of range")));
947 break;
948
951 break;
952
955 break;
956
957 default:
958 elog(ERROR, "unexpected dtype %d while parsing interval \"%s\"",
959 dtype, str);
960 }
961
963
965}
966
967
968
969
972{
974 char *result;
978
981 else
982 {
985 }
986
989}
990
991
992
993
996{
998
999#ifdef NOT_USED
1001#endif
1004
1006
1010
1012
1014}
1015
1016
1017
1018
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1046{
1049 int n;
1051
1053
1054
1055
1056
1057
1058
1059
1060 if (n > 0)
1061 {
1062 switch (tl[0])
1063 {
1078
1079 break;
1080 default:
1083 errmsg("invalid INTERVAL type modifier")));
1084 }
1085 }
1086
1087 if (n == 1)
1088 {
1091 else
1092 typmod = -1;
1093 }
1094 else if (n == 2)
1095 {
1096 if (tl[1] < 0)
1099 errmsg("INTERVAL(%d) precision must not be negative",
1100 tl[1])));
1102 {
1105 errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
1108 }
1109 else
1111 }
1112 else
1113 {
1116 errmsg("invalid INTERVAL type modifier")));
1117 typmod = 0;
1118 }
1119
1121}
1122
1125{
1127 char *res = (char *) palloc(64);
1128 int fields;
1129 int precision;
1131
1132 if (typmod < 0)
1133 {
1134 *res = '\0';
1136 }
1137
1140
1141 switch (fields)
1142 {
1145 break;
1148 break;
1151 break;
1154 break;
1157 break;
1160 break;
1162 fieldstr = " year to month";
1163 break;
1166 break;
1168 fieldstr = " day to minute";
1169 break;
1171 fieldstr = " day to second";
1172 break;
1174 fieldstr = " hour to minute";
1175 break;
1177 fieldstr = " hour to second";
1178 break;
1180 fieldstr = " minute to second";
1181 break;
1184 break;
1185 default:
1186 elog(ERROR, "invalid INTERVAL typmod: 0x%x", typmod);
1188 break;
1189 }
1190
1193 else
1195
1197}
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209static int
1211{
1212 if (typmod < 0)
1213 return 0;
1214
1216 {
1218 return 5;
1220 return 4;
1222 return 3;
1224 return 2;
1226 return 1;
1228 return 0;
1230 return 4;
1232 return 2;
1234 return 1;
1236 return 0;
1238 return 1;
1240 return 0;
1242 return 0;
1244 return 0;
1245 default:
1246 elog(ERROR, "invalid INTERVAL typmod: 0x%x", typmod);
1247 break;
1248 }
1249 return 0;
1250}
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1264{
1267
1269 {
1272 Node *typmod;
1273
1275
1277
1278 if (IsA(typmod, Const) && !((Const *) typmod)->constisnull)
1279 {
1283
1285 noop = true;
1286 else
1287 {
1293
1298 else
1301
1302
1303
1304
1305
1306
1307
1312 }
1315 }
1316 }
1317
1319}
1320
1321
1322
1323
1324
1327{
1331
1334
1336
1338}
1339
1340
1341
1342
1343
1344
1345
1346
1347static bool
1349 Node *escontext)
1350{
1359 };
1360
1369 };
1370
1371
1373 return true;
1374
1375
1376
1377
1378
1379 if (typmod >= 0)
1380 {
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1405 {
1406
1407 }
1409 {
1413 }
1415 {
1418 }
1419
1421 {
1424 }
1426 {
1428 }
1430 {
1433 }
1435 {
1438 }
1440 {
1441
1442 }
1443
1446 {
1449 }
1450
1454 {
1457 }
1458
1463 {
1464
1465 }
1466
1469 {
1472 }
1473
1477 {
1478
1479 }
1480
1483 {
1484
1485 }
1486 else
1487 elog(ERROR, "unrecognized interval typmod: %d", typmod);
1488
1489
1491 {
1493 ereturn(escontext, false,
1495 errmsg("interval(%d) precision must be between %d and %d",
1497
1499 {
1503 ereturn(escontext, false,
1505 errmsg("interval out of range")));
1507 }
1508 else
1509 {
1513 ereturn(escontext, false,
1515 errmsg("interval out of range")));
1517 }
1518 }
1519 }
1520
1521 return true;
1522}
1523
1524
1525
1526
1529{
1538
1539
1540
1541
1542
1545
1547
1548
1552
1553
1557
1558
1560
1561
1566
1567
1570
1572
1576 errmsg("interval out of range"));
1577
1579}
1580
1581
1582
1583
1584void
1586{
1591 else
1592 elog(ERROR, "invalid argument for EncodeSpecialTimestamp");
1593}
1594
1595static void
1597{
1602 else
1603 elog(ERROR, "invalid argument for EncodeSpecialInterval");
1604}
1605
1611
1617
1623
1629
1635
1636
1637
1638
1639
1640
1641
1644{
1647
1649
1653
1654 return result;
1655}
1656
1657
1658
1659
1662{
1664
1666 if (typmod >= 0)
1668 return ts;
1669}
1670
1671
1672
1673
1676{
1678
1680 if (typmod >= 0)
1682 return ts;
1683}
1684
1685
1686
1687
1690{
1692 char templ[128];
1693 char buf[128];
1695
1701
1703}
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718void
1721{
1723
1724 if (diff <= 0)
1725 {
1728 }
1729 else
1730 {
1733 }
1734}
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754long
1756{
1758
1759
1761 return 0;
1762
1767 else
1768 return (long) ((diff + 999) / 1000);
1769}
1770
1771
1772
1773
1774
1775
1776
1777
1778bool
1787
1788
1789
1790
1791
1792bool
1796{
1799
1800
1802
1804}
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1819{
1821
1825
1826 return result;
1827}
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1841{
1843
1846
1847 return result;
1848}
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859const char *
1861{
1863 int tz;
1867 const char *tzn;
1868
1873 else
1874 strlcpy(buf, "(timestamp out of range)", sizeof(buf));
1875
1876 return buf;
1877}
1878
1879
1880void
1882{
1884
1885 time = jd;
1886
1893}
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907int
1909{
1913
1914
1915 if (attimezone == NULL)
1917
1918 time = dt;
1920
1922 {
1925 }
1926
1927
1929
1930
1932 return -1;
1933
1936
1937
1938 if (tzp == NULL)
1939 {
1943 if (tzn != NULL)
1944 *tzn = NULL;
1945 return 0;
1946 }
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1962 {
1964
1975 if (tzn != NULL)
1977 }
1978 else
1979 {
1980
1981
1982
1983 *tzp = 0;
1984
1988 if (tzn != NULL)
1989 *tzn = NULL;
1990 }
1991
1992 return 0;
1993}
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003int
2005{
2008
2009
2011 {
2012 *result = 0;
2013 return -1;
2014 }
2015
2018
2021 {
2022 *result = 0;
2023 return -1;
2024 }
2025 if (tzp != NULL)
2026 *result = dt2local(*result, -(*tzp));
2027
2028
2030 {
2031 *result = 0;
2032 return -1;
2033 }
2034
2035 return 0;
2036}
2037
2038
2039
2040
2041
2042
2043
2044void
2046{
2049
2053 time = span.time;
2054
2064 itm->tm_usec = (int) time;
2065}
2066
2067
2068
2069
2070
2071
2072
2073
2074int
2076{
2078
2080 return -1;
2082 span->day = itm->tm_mday;
2084 &span->time))
2085 return -1;
2086
2088 &span->time))
2089 return -1;
2091 &span->time))
2092 return -1;
2094 &span->time))
2095 return -1;
2097 return -1;
2098 return 0;
2099}
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112int
2114{
2116
2118 return -1;
2122 return 0;
2123}
2124
2130
2133{
2135 return dt;
2136}
2137
2138
2139
2140
2141
2142
2143
2151
2159
2160
2161
2162
2163
2164
2165void
2167{
2170
2172
2174 elog(ERROR, "could not convert epoch to timestamp: %m");
2175
2182
2185}
2186
2189{
2193
2195
2197
2198 return dt;
2199}
2200
2201
2202
2203
2204
2205
2206
2207int
2209{
2210 return (dt1 < dt2) ? -1 : ((dt1 > dt2) ? 1 : 0);
2211}
2212
2221
2230
2239
2248
2257
2266
2275
2284
2285
2288{
2290
2292 {
2293
2295 return (Datum) 0;
2296 }
2297
2300}
2301
2302
2305{
2307
2309 {
2310
2311 *overflow = true;
2312 return (Datum) 0;
2313 }
2314
2315 *overflow = false;
2317}
2318
2331
2337
2343
2349
2355
2356
2357
2358
2359
2362{
2365
2368 {
2370 {
2371
2373 }
2375 {
2376
2378 }
2379 }
2380
2382}
2383
2392
2401
2410
2419
2428
2437
2446
2455
2464
2473
2482
2491
2500
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2523{
2526
2527
2528
2529
2530
2533
2534
2536
2537
2539
2540 return span;
2541}
2542
2543static int
2551
2552static int
2560
2569
2578
2587
2596
2605
2614
2623
2624
2625
2626
2627
2628
2629
2630
2633{
2637
2638
2639
2640
2641
2642
2643
2645
2647}
2648
2651{
2655
2656
2658
2661}
2662
2663
2664
2665
2666
2667
2668
2671{
2672
2673
2674
2675
2676
2685
2686#define TIMESTAMP_GT(t1,t2) \
2687 DatumGetBool(DirectFunctionCall2(timestamp_gt,t1,t2))
2688#define TIMESTAMP_LT(t1,t2) \
2689 DatumGetBool(DirectFunctionCall2(timestamp_lt,t1,t2))
2690
2691
2692
2693
2694
2695
2697 {
2700
2703 }
2705 {
2707 {
2709
2712 }
2713 }
2714
2715
2717 {
2720
2723 }
2725 {
2727 {
2729
2732 }
2733 }
2734
2735
2736
2737
2738
2740 {
2741
2742
2743
2744
2751
2752
2753
2754
2755
2757 }
2759 {
2760
2767
2768
2769
2770
2771
2773 }
2774 else
2775 {
2776
2777
2778
2779
2783 }
2784
2785#undef TIMESTAMP_GT
2786#undef TIMESTAMP_LT
2787}
2788
2789
2790
2791
2792
2793
2796{
2800
2801
2803 result = dt1;
2804 else
2805 result = dt2;
2807}
2808
2811{
2815
2817 result = dt1;
2818 else
2819 result = dt2;
2821}
2822
2823
2826{
2830
2832
2833
2834
2835
2836
2837
2838
2840 {
2842 {
2846 errmsg("interval out of range")));
2847 else
2849 }
2851 {
2855 errmsg("interval out of range")));
2856 else
2858 }
2861 else
2863
2865 }
2866
2870 errmsg("interval out of range")));
2871
2872 result->month = 0;
2873 result->day = 0;
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2902
2904}
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2920{
2925
2930
2931
2934
2935
2936 if ((result->day > 0 && result->time > 0) ||
2937 (result->day < 0 && result->time < 0))
2938 {
2944 errmsg("interval out of range")));
2945 }
2946
2947
2948
2949
2950
2951
2952
2955
2961 errmsg("interval out of range")));
2962
2963 if (result->month > 0 &&
2964 (result->day < 0 || (result->day == 0 && result->time < 0)))
2965 {
2967 result->month--;
2968 }
2969 else if (result->month < 0 &&
2970 (result->day > 0 || (result->day == 0 && result->time > 0)))
2971 {
2973 result->month++;
2974 }
2975
2976 if (result->day > 0 && result->time < 0)
2977 {
2979 result->day--;
2980 }
2981 else if (result->day < 0 && result->time > 0)
2982 {
2984 result->day++;
2985 }
2986
2988}
2989
2990
2991
2992
2993
2994
2995
2996
2997
3000{
3004
3009
3010
3013
3018 errmsg("interval out of range")));
3019
3020 if (result->day > 0 && result->time < 0)
3021 {
3023 result->day--;
3024 }
3025 else if (result->day < 0 && result->time > 0)
3026 {
3028 result->day++;
3029 }
3030
3032}
3033
3034
3035
3036
3037
3038
3039
3042{
3046
3051
3052
3055
3061 errmsg("interval out of range")));
3062
3063 if (result->month > 0 && result->day < 0)
3064 {
3066 result->month--;
3067 }
3068 else if (result->month < 0 && result->day > 0)
3069 {
3071 result->month++;
3072 }
3073
3075}
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3089{
3093
3094
3095
3096
3097
3098
3099
3101 {
3105 errmsg("timestamp out of range")));
3106 else
3108 }
3110 {
3114 errmsg("timestamp out of range")));
3115 else
3117 }
3120 else
3121 {
3122 if (span->month != 0)
3123 {
3127
3131 errmsg("timestamp out of range")));
3132
3136 errmsg("timestamp out of range")));
3138 {
3141 }
3143 {
3146 }
3147
3148
3151
3155 errmsg("timestamp out of range")));
3156 }
3157
3158 if (span->day != 0)
3159 {
3164
3168 errmsg("timestamp out of range")));
3169
3170
3171
3172
3173
3179 errmsg("timestamp out of range")));
3181
3185 errmsg("timestamp out of range")));
3186 }
3187
3191 errmsg("timestamp out of range")));
3192
3196 errmsg("timestamp out of range")));
3197
3199 }
3200
3202}
3203
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3233 pg_tz *attimezone)
3234{
3236 int tz;
3237
3238
3239
3240
3241
3242
3243
3245 {
3249 errmsg("timestamp out of range")));
3250 else
3252 }
3254 {
3258 errmsg("timestamp out of range")));
3259 else
3261 }
3264 else
3265 {
3266
3267 if (attimezone == NULL)
3269
3270 if (span->month != 0)
3271 {
3275
3279 errmsg("timestamp out of range")));
3280
3284 errmsg("timestamp out of range")));
3286 {
3289 }
3291 {
3294 }
3295
3296
3299
3301
3305 errmsg("timestamp out of range")));
3306 }
3307
3308 if (span->day != 0)
3309 {
3314
3318 errmsg("timestamp out of range")));
3319
3320
3321
3322
3323
3324
3325
3326
3332 errmsg("timestamp out of range")));
3334
3336
3340 errmsg("timestamp out of range")));
3341 }
3342
3346 errmsg("timestamp out of range")));
3347
3351 errmsg("timestamp out of range")));
3352
3354 }
3355
3356 return result;
3357}
3358
3359
3360
3361
3365 pg_tz *attimezone)
3366{
3368
3370
3372}
3373
3374
3375
3376
3385
3394
3395
3396
3397
3408
3419
3420
3421
3422
3423static void
3425{
3430 else
3431 {
3432
3439 errmsg("interval out of range")));
3440 }
3441}
3442
3454
3455
3458{
3462
3463
3466 else
3469}
3470
3473{
3477
3480 else
3483}
3484
3485static void
3487{
3490
3497 errmsg("interval out of range")));
3498}
3499
3502{
3506
3508
3509
3510
3511
3512
3513
3514
3516 {
3520 errmsg("interval out of range")));
3521 else
3523 }
3525 {
3529 errmsg("interval out of range")));
3530 else
3532 }
3535 else
3537
3539}
3540
3541static void
3543{
3546
3553 errmsg("interval out of range")));
3554}
3555
3558{
3562
3564
3565
3566
3567
3568
3569
3570
3572 {
3576 errmsg("interval out of range")));
3577 else
3579 }
3581 {
3585 errmsg("interval out of range")));
3586 else
3588 }
3593 else
3595
3597}
3598
3599
3600
3601
3602
3603
3604
3607{
3616
3618
3619
3620
3621
3622
3623
3624
3627
3629 {
3632
3635 else
3637
3639 }
3641 {
3643
3646
3649 else
3651
3653 }
3654
3659
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3688
3689
3690
3691
3692
3693
3695 {
3698 &result->day))
3701 }
3702
3703
3705 &result->day))
3711
3714
3716
3720 errmsg("interval out of range"));
3721
3723}
3724
3734
3737{
3746
3748
3752 errmsg("division by zero")));
3753
3754
3755
3756
3757
3758
3759
3760
3763
3765 {
3768
3771 else
3773
3775 }
3776
3781
3786
3787
3788
3789
3796 {
3799 &result->day))
3802 }
3803
3804
3806 &result->day))
3812
3815
3817
3821 errmsg("interval out of range"));
3822
3824}
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3838{
3845
3849 errmsg("invalid preceding or following size in window function")));
3850
3851
3852
3853
3854
3855
3856
3860
3861
3862 if (sub)
3864 else
3866
3869 else
3871}
3872
3875{
3882
3886 errmsg("invalid preceding or following size in window function")));
3887
3888
3889
3890
3891
3892
3893
3897
3898
3899 if (sub)
3903 else
3907
3910 else
3912}
3913
3916{
3923
3927 errmsg("invalid preceding or following size in window function")));
3928
3929
3930
3931
3932
3933
3934
3938
3939
3940 if (sub)
3944 else
3948
3951 else
3953}
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3966{
3970
3972 elog(ERROR, "aggregate function called in non-aggregate context");
3973
3975
3977
3979
3981}
3982
3983
3984
3985
3986static void
3988{
3989
3991 {
3992 state->nInfcount++;
3993 return;
3994 }
3995
3997 {
3998 state->pInfcount++;
3999 return;
4000 }
4001
4004}
4005
4006
4007
4008
4009static void
4011{
4012
4014 {
4015 state->nInfcount--;
4016 return;
4017 }
4018
4020 {
4021 state->pInfcount--;
4022 return;
4023 }
4024
4025
4027 if (state->N > 0)
4029 else
4030 {
4031
4034 }
4035}
4036
4037
4038
4039
4042{
4044
4046
4047
4050
4053
4055}
4056
4057
4058
4059
4060
4061
4062
4065{
4068
4071
4074
4076 {
4077
4079
4083
4087
4089 }
4090
4094
4095
4098
4100}
4101
4102
4103
4104
4105
4108{
4112
4113
4115 elog(ERROR, "aggregate function called in non-aggregate context");
4116
4118
4120
4121
4123
4124
4128
4129
4131
4132
4134
4136
4138}
4139
4140
4141
4142
4143
4146{
4150
4152 elog(ERROR, "aggregate function called in non-aggregate context");
4153
4155
4156
4157
4158
4159
4162
4164
4165
4167
4168
4172
4173
4175
4176
4178
4180
4182}
4183
4184
4185
4186
4189{
4191
4193
4194
4196 elog(ERROR, "interval_avg_accum_inv called with NULL state");
4197
4200
4202}
4203
4204
4207{
4209
4211
4212
4215
4216
4217
4218
4219
4220
4221 if (state->pInfcount > 0 || state->nInfcount > 0)
4222 {
4224
4225 if (state->pInfcount > 0 && state->nInfcount > 0)
4228 errmsg("interval out of range")));
4229
4231 if (state->pInfcount > 0)
4233 else
4235
4237 }
4238
4242}
4243
4244
4247{
4250
4252
4253
4256
4257
4258
4259
4260
4261
4262 if (state->pInfcount > 0 && state->nInfcount > 0)
4265 errmsg("interval out of range")));
4266
4268
4269 if (state->pInfcount > 0)
4271 else if (state->nInfcount > 0)
4273 else
4275
4277}
4278
4279
4280
4281
4282
4283
4284
4287{
4299
4301
4302
4303
4304
4305
4306
4307
4309 {
4313 errmsg("interval out of range")));
4314 else
4316 }
4318 {
4322 errmsg("interval out of range")));
4323 else
4325 }
4332 {
4333
4341
4342
4344 {
4345 tm->tm_usec = -tm->tm_usec;
4352 }
4353
4354
4355 while (tm->tm_usec < 0)
4356 {
4359 }
4360
4362 {
4365 }
4366
4368 {
4371 }
4372
4374 {
4377 }
4378
4380 {
4382 {
4385 }
4386 else
4387 {
4390 }
4391 }
4392
4394 {
4397 }
4398
4399
4401 {
4402 tm->tm_usec = -tm->tm_usec;
4409 }
4410
4414 errmsg("interval out of range")));
4415 }
4416 else
4419 errmsg("timestamp out of range")));
4420
4422}
4423
4424
4425
4426
4427
4428
4429
4430
4433{
4445 int tz1;
4446 int tz2;
4447
4449
4450
4451
4452
4453
4454
4455
4457 {
4461 errmsg("interval out of range")));
4462 else
4464 }
4466 {
4470 errmsg("interval out of range")));
4471 else
4473 }
4480 {
4481
4489
4490
4492 {
4493 tm->tm_usec = -tm->tm_usec;
4500 }
4501
4502
4503 while (tm->tm_usec < 0)
4504 {
4507 }
4508
4510 {
4513 }
4514
4516 {
4519 }
4520
4522 {
4525 }
4526
4528 {
4530 {
4533 }
4534 else
4535 {
4538 }
4539 }
4540
4542 {
4545 }
4546
4547
4548
4549
4550
4551
4553 {
4554 tm->tm_usec = -tm->tm_usec;
4561 }
4562
4566 errmsg("interval out of range")));
4567 }
4568 else
4571 errmsg("timestamp out of range")));
4572
4574}
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4587{
4596
4599
4603 errmsg("origin out of range")));
4604
4608 errmsg("timestamps cannot be binned into infinite intervals")));
4609
4610 if (stride->month != 0)
4613 errmsg("timestamps cannot be binned into intervals containing months or years")));
4614
4619 errmsg("interval out of range")));
4620
4624 errmsg("stride must be greater than zero")));
4625
4629 errmsg("interval out of range")));
4630
4631
4635
4636
4637
4638
4639
4640
4642 {
4647 errmsg("timestamp out of range")));
4648 }
4649
4651}
4652
4653
4654
4655
4658{
4668
4671 false);
4672
4674
4676 {
4678 {
4679
4680
4681
4682
4683
4684 switch (val)
4685 {
4700 break;
4701 default:
4704 errmsg("unit \"%s\" not supported for type %s",
4706 result = 0;
4707 }
4708 }
4709
4713 errmsg("timestamp out of range")));
4714
4715 switch (val)
4716 {
4718 {
4719 int woy;
4720
4722
4723
4724
4725
4726
4727
4736 fsec = 0;
4737 break;
4738 }
4740
4743 else
4747
4750 else
4754
4756 {
4759 else
4761 }
4782 fsec = 0;
4783 break;
4784
4786 fsec = (fsec / 1000) * 1000;
4787 break;
4788
4790 break;
4791
4792 default:
4795 errmsg("unit \"%s\" not supported for type %s",
4797 result = 0;
4798 }
4799
4803 errmsg("timestamp out of range")));
4804 }
4805 else
4806 {
4809 errmsg("unit \"%s\" not recognized for type %s",
4811 result = 0;
4812 }
4813
4815}
4816
4817
4818
4819
4822{
4831
4834
4838 errmsg("origin out of range")));
4839
4843 errmsg("timestamps cannot be binned into infinite intervals")));
4844
4845 if (stride->month != 0)
4848 errmsg("timestamps cannot be binned into intervals containing months or years")));
4849
4854 errmsg("interval out of range")));
4855
4859 errmsg("stride must be greater than zero")));
4860
4864 errmsg("interval out of range")));
4865
4866
4870
4871
4872
4873
4874
4875
4877 {
4882 errmsg("timestamp out of range")));
4883 }
4884
4886}
4887
4888
4889
4890
4891
4892
4893
4896{
4898 int tz;
4901 bool redotz = false;
4906
4909 false);
4910
4912
4914 {
4916 {
4917
4918
4919
4920
4921
4922 switch (val)
4923 {
4938 break;
4939
4940 default:
4943 errmsg("unit \"%s\" not supported for type %s",
4945 result = 0;
4946 }
4947 }
4948
4952 errmsg("timestamp out of range")));
4953
4954 switch (val)
4955 {
4957 {
4958 int woy;
4959
4961
4962
4963
4964
4965
4966
4975 fsec = 0;
4977 break;
4978 }
4979
4981
4982
4983
4984
4985
4986
4989 else
4993
4996 else
5000
5001
5002
5003
5004
5006 {
5009 else
5011 }
5024 redotz = true;
5033 fsec = 0;
5034 break;
5036 fsec = (fsec / 1000) * 1000;
5037 break;
5039 break;
5040
5041 default:
5044 errmsg("unit \"%s\" not supported for type %s",
5046 result = 0;
5047 }
5048
5051
5055 errmsg("timestamp out of range")));
5056 }
5057 else
5058 {
5061 errmsg("unit \"%s\" not recognized for type %s",
5063 result = 0;
5064 }
5065
5066 return result;
5067}
5068
5069
5070
5071
5083
5084
5085
5086
5089{
5095
5096
5097
5098
5100
5102
5104}
5105
5106
5107
5108
5111{
5120
5122
5125 false);
5126
5128
5130 {
5132 {
5133
5134
5135
5136
5137
5138 switch (val)
5139 {
5154 break;
5155
5156 default:
5159 errmsg("unit \"%s\" not supported for type %s",
5161 (val == DTK_WEEK) ? errdetail("Months usually have fractional weeks.") : 0));
5162 result = NULL;
5163 }
5164 }
5165
5167 switch (val)
5168 {
5170
5174
5178
5200 tm->tm_usec = 0;
5201 break;
5203 tm->tm_usec = (tm->tm_usec / 1000) * 1000;
5204 break;
5206 break;
5207
5208 default:
5211 errmsg("unit \"%s\" not supported for type %s",
5213 (val == DTK_WEEK) ? errdetail("Months usually have fractional weeks.") : 0));
5214 }
5215
5219 errmsg("interval out of range")));
5220 }
5221 else
5222 {
5225 errmsg("unit \"%s\" not recognized for type %s",
5227 }
5228
5230}
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241int
5243{
5246
5247
5249
5250
5252
5254}
5255
5256
5257
5258
5259
5260
5261void
5266
5267
5268
5269
5270
5271
5272
5273
5274void
5276{
5278
5280
5281 if (wday > 1)
5282 jday += wday - 2;
5283 else
5286}
5287
5288
5289
5290
5291
5292int
5294{
5299
5300
5302
5303
5305
5306
5308
5309
5310
5311
5312
5314 {
5316
5317
5319 }
5320
5322
5323
5324
5325
5326
5327 if (week >= 52)
5328 {
5330
5331
5333
5336 }
5337
5338 return week;
5339}
5340
5341
5342
5343
5344
5345
5346
5347int
5349{
5354
5355
5357
5358
5360
5361
5363
5364
5365
5366
5367
5369 {
5371
5372
5374
5375 year--;
5376 }
5377
5379
5380
5381
5382
5383
5384 if (week >= 52)
5385 {
5387
5388
5390
5392 year++;
5393 }
5394
5395 return year;
5396}
5397
5398
5399
5400
5401
5402
5403
5404int
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5424{
5428 errmsg("unit \"%s\" not recognized for type %s",
5431
5432 switch (unit)
5433 {
5434
5450 return 0.0;
5451
5452
5462 else
5464
5465 default:
5468 errmsg("unit \"%s\" not supported for type %s",
5471 return 0.0;
5472 }
5473}
5474
5475
5476
5477
5480{
5491
5494 false);
5495
5499
5501 {
5504 false);
5505
5506 if (r != 0.0)
5507 {
5509 {
5510 if (r < 0)
5515 else if (r > 0)
5520 }
5521 else
5523 }
5524 else
5526 }
5527
5529 {
5533 errmsg("timestamp out of range")));
5534
5535 switch (val)
5536 {
5539 break;
5540
5543
5544
5545
5546
5548 else
5550 break;
5551
5554
5555
5556
5557
5559 else
5561 break;
5562
5565 break;
5566
5569 break;
5570
5573 break;
5574
5577 break;
5578
5581 break;
5582
5585 break;
5586
5590 else
5591
5593 break;
5594
5596
5597
5598
5599
5600
5601
5604 else
5606 break;
5607
5609
5610
5611
5612
5613
5614
5615
5618 else
5619
5621 break;
5622
5624
5627 else
5629 break;
5630
5638 else
5642 break;
5643
5646
5649 break;
5650
5656 break;
5657
5661 break;
5662
5666 default:
5669 errmsg("unit \"%s\" not supported for type %s",
5672 }
5673 }
5675 {
5676 switch (val)
5677 {
5680
5682 {
5684
5687 else
5688 {
5697 }
5699 }
5700 else
5701 {
5703
5704
5707 else
5710 }
5711 break;
5712
5713 default:
5716 errmsg("unit \"%s\" not supported for type %s",
5719 }
5720 }
5721 else
5722 {
5725 errmsg("unit \"%s\" not recognized for type %s",
5728 }
5729
5732 else
5734}
5735
5741
5747
5748
5749
5750
5753{
5758 int tz;
5765
5768 false);
5769
5773
5775 {
5778 true);
5779
5780 if (r != 0.0)
5781 {
5783 {
5784 if (r < 0)
5789 else if (r > 0)
5794 }
5795 else
5797 }
5798 else
5800 }
5801
5803 {
5807 errmsg("timestamp out of range")));
5808
5809 switch (val)
5810 {
5813 break;
5814
5817 break;
5818
5821 break;
5822
5825 break;
5826
5829
5830
5831
5832
5834 else
5836 break;
5837
5840
5841
5842
5843
5845 else
5847 break;
5848
5851 break;
5852
5855 break;
5856
5859 break;
5860
5863 break;
5864
5867 break;
5868
5871 break;
5872
5876 else
5877
5879 break;
5880
5882
5885 else
5887 break;
5888
5890
5893 else
5895 break;
5896
5898
5901 else
5903 break;
5904
5912 else
5916 break;
5917
5920
5923 break;
5924
5930 break;
5931
5935 break;
5936
5937 default:
5940 errmsg("unit \"%s\" not supported for type %s",
5943 }
5944 }
5946 {
5947 switch (val)
5948 {
5951
5953 {
5955
5958 else
5959 {
5968 }
5970 }
5971 else
5972 {
5974
5975
5978 else
5981 }
5982 break;
5983
5984 default:
5987 errmsg("unit \"%s\" not supported for type %s",
5990 }
5991 }
5992 else
5993 {
5996 errmsg("unit \"%s\" not recognized for type %s",
5998
6000 }
6001
6004 else
6006}
6007
6013
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6033{
6037 errmsg("unit \"%s\" not recognized for type %s",
6039
6040 switch (unit)
6041 {
6042
6050 return 0.0;
6051
6052
6062 else
6064
6065 default:
6068 errmsg("unit \"%s\" not supported for type %s",
6070 return 0.0;
6071 }
6072}
6073
6074
6075
6076
6079{
6088
6091 false);
6092
6096
6098 {
6101
6102 if (r != 0.0)
6103 {
6105 {
6106 if (r < 0)
6111 else if (r > 0)
6116 }
6117 else
6119 }
6120 else
6122 }
6123
6125 {
6127 switch (val)
6128 {
6131 break;
6132
6135
6136
6137
6138
6140 else
6142 break;
6143
6146
6147
6148
6149
6151 else
6153 break;
6154
6157 break;
6158
6161 break;
6162
6165 break;
6166
6169 break;
6170
6173 break;
6174
6176
6177
6178
6179
6180
6181
6182
6183
6186 else
6188 break;
6189
6192 break;
6193
6195
6197 break;
6198
6200
6202 break;
6203
6205
6207 break;
6208
6209 default:
6212 errmsg("unit \"%s\" not supported for type %s",
6215 }
6216 }
6218 {
6220 {
6224
6225
6226
6227
6228
6229
6230
6231
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6249 else
6250 result =
6254
6256 }
6257 else
6258 {
6260
6265
6267 }
6268 }
6269 else
6270 {
6273 errmsg("unit \"%s\" not recognized for type %s",
6276 }
6277
6280 else
6282}
6283
6289
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6307{
6311 int tz;
6318
6321
6322
6323
6324
6326
6328
6330 {
6331
6332 tz = val;
6334 }
6336 {
6337
6341 errmsg("timestamp out of range")));
6344 }
6345 else
6346 {
6347
6351 errmsg("timestamp out of range")));
6356 errmsg("timestamp out of range")));
6357 }
6358
6362 errmsg("timestamp out of range")));
6363
6365}
6366
6367
6368
6369
6372{
6376 int tz;
6377
6380
6384 errmsg("interval time zone \"%s\" must be finite",
6387
6388 if (zone->month != 0 || zone->day != 0)
6391 errmsg("interval time zone \"%s\" must not include months or days",
6394
6396
6398
6402 errmsg("timestamp out of range")));
6403
6405}
6406
6407
6408
6409
6410
6411
6412
6413
6414bool
6416{
6417 long offset;
6418
6420 return false;
6421 return true;
6422}
6423
6424
6425
6426
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6447{
6452 int tz;
6453
6456
6457
6459 {
6461
6463
6465 return result;
6466 }
6467
6470 else
6472
6473 ereturn(escontext, result,
6475 errmsg("timestamp out of range")));
6476}
6477
6478
6479
6480
6486
6487
6488
6489
6497
6498
6499
6500
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6519{
6524 int tz;
6525
6528 else
6529 {
6531 {
6534 else
6536
6537 ereturn(escontext, result,
6539 errmsg("timestamp out of range")));
6540 }
6542 {
6545 else
6547
6548 ereturn(escontext, result,
6550 errmsg("timestamp out of range")));
6551 }
6552 }
6553 return result;
6554}
6555
6556
6557
6558
6559
6562{
6566 int tz;
6571
6574
6575
6576
6577
6579
6581
6583 {
6584
6585 tz = -val;
6587 }
6589 {
6590
6592
6595 }
6596 else
6597 {
6598
6601
6605 errmsg("timestamp out of range")));
6609 errmsg("timestamp out of range")));
6610 }
6611
6615 errmsg("timestamp out of range")));
6616
6618}
6619
6620
6621
6622
6623
6626{
6630 int tz;
6631
6634
6638 errmsg("interval time zone \"%s\" must be finite",
6641
6642 if (zone->month != 0 || zone->day != 0)
6645 errmsg("interval time zone \"%s\" must not include months or days",
6648
6650
6652
6656 errmsg("timestamp out of range")));
6657
6659}
6660
6661
6662
6663
6666{
6670
6671
6673 {
6678
6679
6681
6682
6683
6684
6686
6687
6689
6690
6691
6692
6693
6695 fctx->finish = finish;
6696 fctx->step = *step;
6697
6698
6700
6701 if (fctx->step_sign == 0)
6704 errmsg("step size cannot equal zero")));
6705
6709 errmsg("step size cannot be infinite")));
6710
6713 }
6714
6715
6717
6718
6719
6720
6722 result = fctx->current;
6723
6724 if (fctx->step_sign > 0 ?
6727 {
6728
6732
6733
6735 }
6736 else
6737 {
6738
6740 }
6741}
6742
6743
6744
6745
6746
6749{
6753
6754
6756 {
6762
6763
6765
6766
6767
6768
6770
6771
6773
6774
6775
6776
6777
6779 fctx->finish = finish;
6780 fctx->step = *step;
6782
6783
6785
6786 if (fctx->step_sign == 0)
6789 errmsg("step size cannot equal zero")));
6790
6794 errmsg("step size cannot be infinite")));
6795
6798 }
6799
6800
6802
6803
6804
6805
6807 result = fctx->current;
6808
6809 if (fctx->step_sign > 0 ?
6812 {
6813
6815 &fctx->step,
6816 fctx->attimezone);
6817
6818
6820 }
6821 else
6822 {
6823
6825 }
6826}
6827
6833
6839
6840
6841
6842
6845{
6848
6850 {
6851
6853
6855 {
6860
6861
6865
6866
6867
6868
6869
6870
6871
6875 {
6876 req->rows = 0;
6878 }
6880 {
6882 finish;
6887
6891
6892
6893
6894
6895
6896
6899 {
6903
6904#define INTERVAL_TO_MICROSECONDS(i) ((((double) (i)->month * DAYS_PER_MONTH + (i)->day)) * USECS_PER_DAY + (i)->time)
6905
6907
6908
6909 if (dstep != 0.0)
6910 {
6913
6916 }
6917#undef INTERVAL_TO_MICROSECONDS
6918 }
6919 }
6920 }
6921 }
6922
6924}
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6940
#define PG_GETARG_ARRAYTYPE_P(n)
int32 * ArrayGetIntegerTypmods(ArrayType *arr, int *n)
Node * TemporalSimplify(int32 max_precis, Node *node)
pg_tz * DecodeTimezoneNameToTz(const char *tzname)
int DetermineTimeZoneAbbrevOffsetTS(TimestampTz ts, const char *abbr, pg_tz *tzp, int *isdst)
int DecodeUnits(int field, const char *lowtoken, int *val)
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
void EncodeInterval(struct pg_itm *itm, int style, char *str)
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
void DateTimeParseError(int dterr, DateTimeErrorExtra *extra, const char *str, const char *datatype, Node *escontext)
int DecodeInterval(char **field, int *ftype, int nf, int range, int *dtype, struct pg_itm_in *itm_in)
int DecodeISO8601Interval(char *str, int *dtype, struct pg_itm_in *itm_in)
int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc, struct pg_tm *tm)
int DecodeSpecial(int field, const char *lowtoken, int *val)
void j2date(int jd, int *year, int *month, int *day)
void EncodeDateTime(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str)
int DecodeTimezone(const char *str, int *tzp)
const char *const months[]
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, DateTimeErrorExtra *extra)
int date2j(int year, int month, int day)
int DecodeTimezoneName(const char *tzname, int *offset, pg_tz **tz)
int DetermineTimeZoneAbbrevOffset(struct pg_tm *tm, const char *abbr, pg_tz *tzp)
Datum numeric_round(PG_FUNCTION_ARGS)
Numeric int64_to_numeric(int64 val)
Numeric numeric_add_safe(Numeric num1, Numeric num2, Node *escontext)
Numeric int64_div_fast_to_numeric(int64 val1, int log10val2)
Numeric numeric_div_safe(Numeric num1, Numeric num2, Node *escontext)
Numeric numeric_sub_safe(Numeric num1, Numeric num2, Node *escontext)
Datum numeric_in(PG_FUNCTION_ARGS)
void dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
Datum interval_out(PG_FUNCTION_ARGS)
Datum interval_justify_hours(PG_FUNCTION_ARGS)
Datum make_timestamptz_at_timezone(PG_FUNCTION_ARGS)
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
long TimestampDifferenceMilliseconds(TimestampTz start_time, TimestampTz stop_time)
void isoweek2date(int woy, int *year, int *mon, int *mday)
Datum in_range_timestamp_interval(PG_FUNCTION_ARGS)
void GetEpochTime(struct pg_tm *tm)
Datum generate_series_timestamptz(PG_FUNCTION_ARGS)
static float8 NonFiniteTimestampTzPart(int type, int unit, char *lowunits, bool isNegative, bool isTz)
static INT128 interval_cmp_value(const Interval *interval)
Datum interval_trunc(PG_FUNCTION_ARGS)
Datum overlaps_timestamp(PG_FUNCTION_ARGS)
Datum extract_timestamp(PG_FUNCTION_ARGS)
Datum timestamptypmodout(PG_FUNCTION_ARGS)
Datum interval_gt(PG_FUNCTION_ARGS)
Datum interval_avg_accum(PG_FUNCTION_ARGS)
int itmin2interval(struct pg_itm_in *itm_in, Interval *span)
Datum interval_justify_interval(PG_FUNCTION_ARGS)
static void finite_interval_mi(const Interval *span1, const Interval *span2, Interval *result)
Datum timestamptz_part(PG_FUNCTION_ARGS)
int isoweek2j(int year, int week)
Datum clock_timestamp(PG_FUNCTION_ARGS)
Datum timestamptz_pl_interval_at_zone(PG_FUNCTION_ARGS)
Datum timestamp_pl_interval(PG_FUNCTION_ARGS)
Datum interval_le(PG_FUNCTION_ARGS)
Datum interval_avg_serialize(PG_FUNCTION_ARGS)
Datum interval_mi(PG_FUNCTION_ARGS)
TimestampTz time_t_to_timestamptz(pg_time_t tm)
Datum timestamp_le_timestamptz(PG_FUNCTION_ARGS)
Datum interval_lt(PG_FUNCTION_ARGS)
Datum timestamp_larger(PG_FUNCTION_ARGS)
static Datum timestamptz_part_common(PG_FUNCTION_ARGS, bool retnumeric)
Datum timestamptz_izone(PG_FUNCTION_ARGS)
Datum timestamp_cmp_timestamptz(PG_FUNCTION_ARGS)
static bool AdjustIntervalForTypmod(Interval *interval, int32 typmod, Node *escontext)
Datum timestamp_part(PG_FUNCTION_ARGS)
Datum timestamptz_eq_timestamp(PG_FUNCTION_ARGS)
Datum interval_hash(PG_FUNCTION_ARGS)
Datum timestamptztypmodout(PG_FUNCTION_ARGS)
int date2isoweek(int year, int mon, int mday)
Datum timestamptz_pl_interval(PG_FUNCTION_ARGS)
Datum timestamp_cmp(PG_FUNCTION_ARGS)
static TimestampTz timestamptz_trunc_internal(text *units, TimestampTz timestamp, pg_tz *tzp)
Datum timestamp_bin(PG_FUNCTION_ARGS)
Datum timestamp_zone(PG_FUNCTION_ARGS)
static pg_tz * lookup_timezone(text *zone)
static TimestampTz timestamp2timestamptz(Timestamp timestamp)
Datum interval_finite(PG_FUNCTION_ARGS)
Datum timestamptz_ne_timestamp(PG_FUNCTION_ARGS)
Datum timestamptz_lt_timestamp(PG_FUNCTION_ARGS)
Datum timestamp_sortsupport(PG_FUNCTION_ARGS)
Datum timestamp_mi_interval(PG_FUNCTION_ARGS)
Datum timestamptypmodin(PG_FUNCTION_ARGS)
bool AdjustTimestampForTypmod(Timestamp *time, int32 typmod, Node *escontext)
Datum timestamptz_ge_timestamp(PG_FUNCTION_ARGS)
Datum timestamp_smaller(PG_FUNCTION_ARGS)
Datum interval_justify_days(PG_FUNCTION_ARGS)
TimestampTz timestamp2timestamptz_safe(Timestamp timestamp, Node *escontext)
Datum timestamp_ge(PG_FUNCTION_ARGS)
Datum interval_avg_accum_inv(PG_FUNCTION_ARGS)
Datum generate_series_timestamp(PG_FUNCTION_ARGS)
int date2isoyearday(int year, int mon, int mday)
Datum timestamptz_cmp_timestamp(PG_FUNCTION_ARGS)
Datum timestamp_ge_timestamptz(PG_FUNCTION_ARGS)
static Timestamp timestamptz2timestamp(TimestampTz timestamp)
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
static void do_interval_accum(IntervalAggState *state, Interval *newval)
Datum timestamp_scale(PG_FUNCTION_ARGS)
Datum timestamptz_scale(PG_FUNCTION_ARGS)
Datum make_timestamptz(PG_FUNCTION_ARGS)
bool TimestampDifferenceExceedsSeconds(TimestampTz start_time, TimestampTz stop_time, int threshold_sec)
bool TimestampTimestampTzRequiresRewrite(void)
Datum timestamp_timestamptz(PG_FUNCTION_ARGS)
Datum timestamp_recv(PG_FUNCTION_ARGS)
Datum timestamp_lt(PG_FUNCTION_ARGS)
Datum timestamptz_trunc(PG_FUNCTION_ARGS)
Datum timestamptz_zone(PG_FUNCTION_ARGS)
static void finite_interval_pl(const Interval *span1, const Interval *span2, Interval *result)
void isoweekdate2date(int isoweek, int wday, int *year, int *mon, int *mday)
int32 timestamp_cmp_timestamptz_internal(Timestamp timestampVal, TimestampTz dt2)
Datum timestamptz_gt_timestamp(PG_FUNCTION_ARGS)
Datum timestamptz_hash_extended(PG_FUNCTION_ARGS)
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
static int32 anytimestamp_typmodin(bool istz, ArrayType *ta)
Datum generate_series_timestamp_support(PG_FUNCTION_ARGS)
Datum interval_cmp(PG_FUNCTION_ARGS)
Datum interval_sum(PG_FUNCTION_ARGS)
Datum timestamp_hash_extended(PG_FUNCTION_ARGS)
Datum timestamptz_le_timestamp(PG_FUNCTION_ARGS)
Datum interval_pl(PG_FUNCTION_ARGS)
Datum interval_um(PG_FUNCTION_ARGS)
Datum timestamp_skipsupport(PG_FUNCTION_ARGS)
static float8 NonFiniteIntervalPart(int type, int unit, char *lowunits, bool isNegative)
void EncodeSpecialTimestamp(Timestamp dt, char *str)
Datum make_interval(PG_FUNCTION_ARGS)
static char * anytimestamp_typmodout(bool istz, int32 typmod)
Datum interval_ge(PG_FUNCTION_ARGS)
static Timestamp make_timestamp_internal(int year, int month, int day, int hour, int min, double sec)
Datum timestamp_gt_timestamptz(PG_FUNCTION_ARGS)
Datum timestamp_in(PG_FUNCTION_ARGS)
Datum timestamp_le(PG_FUNCTION_ARGS)
Datum interval_ne(PG_FUNCTION_ARGS)
Datum timestamptz_hash(PG_FUNCTION_ARGS)
Datum interval_in(PG_FUNCTION_ARGS)
static Timestamp dt2local(Timestamp dt, int timezone)
static Datum interval_part_common(PG_FUNCTION_ARGS, bool retnumeric)
Datum timestamp_ne_timestamptz(PG_FUNCTION_ARGS)
Datum interval_hash_extended(PG_FUNCTION_ARGS)
Datum timestamptz_mi_interval(PG_FUNCTION_ARGS)
Datum timestamp_age(PG_FUNCTION_ARGS)
Datum interval_smaller(PG_FUNCTION_ARGS)
static void EncodeSpecialInterval(const Interval *interval, char *str)
Datum timestamptz_mi_interval_at_zone(PG_FUNCTION_ARGS)
Datum interval_support(PG_FUNCTION_ARGS)
Datum timestamptz_in(PG_FUNCTION_ARGS)
static int intervaltypmodleastfield(int32 typmod)
int32 anytimestamp_typmod_check(bool istz, int32 typmod)
Datum extract_timestamptz(PG_FUNCTION_ARGS)
Datum pg_postmaster_start_time(PG_FUNCTION_ARGS)
TimestampTz GetCurrentTimestamp(void)
static TimeOffset time2t(const int hour, const int min, const int sec, const fsec_t fsec)
Datum interval_part(PG_FUNCTION_ARGS)
Datum pg_conf_load_time(PG_FUNCTION_ARGS)
Datum in_range_interval_interval(PG_FUNCTION_ARGS)
#define IA_TOTAL_COUNT(ia)
const char * timestamptz_to_str(TimestampTz t)
Datum interval_eq(PG_FUNCTION_ARGS)
static Datum timestamp_increment(Relation rel, Datum existing, bool *overflow)
Timestamp GetSQLLocalTimestamp(int32 typmod)
Datum timestamp_finite(PG_FUNCTION_ARGS)
static TimestampTz timestamptz_mi_interval_internal(TimestampTz timestamp, Interval *span, pg_tz *attimezone)
Datum timestamp_trunc(PG_FUNCTION_ARGS)
Datum mul_d_interval(PG_FUNCTION_ARGS)
Datum timestamptztypmodin(PG_FUNCTION_ARGS)
Datum interval_avg(PG_FUNCTION_ARGS)
Datum timestamp_send(PG_FUNCTION_ARGS)
Datum timestamptz_send(PG_FUNCTION_ARGS)
Datum timestamptz_recv(PG_FUNCTION_ARGS)
Datum interval_scale(PG_FUNCTION_ARGS)
static Datum timestamp_part_common(PG_FUNCTION_ARGS, bool retnumeric)
Datum interval_larger(PG_FUNCTION_ARGS)
Datum timestamp_gt(PG_FUNCTION_ARGS)
static IntervalAggState * makeIntervalAggState(FunctionCallInfo fcinfo)
Datum timestamptz_bin(PG_FUNCTION_ARGS)
Datum timestamptz_timestamp(PG_FUNCTION_ARGS)
Datum timestamp_mi(PG_FUNCTION_ARGS)
Datum timestamptz_at_local(PG_FUNCTION_ARGS)
Datum interval_send(PG_FUNCTION_ARGS)
Datum intervaltypmodin(PG_FUNCTION_ARGS)
#define TIMESTAMP_GT(t1, t2)
Datum timestamp_lt_timestamptz(PG_FUNCTION_ARGS)
Datum timestamptz_out(PG_FUNCTION_ARGS)
static void interval_um_internal(const Interval *interval, Interval *result)
Datum timestamp_hash(PG_FUNCTION_ARGS)
Datum timestamp_out(PG_FUNCTION_ARGS)
Datum timestamp_support(PG_FUNCTION_ARGS)
void interval2itm(Interval span, struct pg_itm *itm)
Datum float8_timestamptz(PG_FUNCTION_ARGS)
Datum now(PG_FUNCTION_ARGS)
Datum interval_avg_deserialize(PG_FUNCTION_ARGS)
Datum timestamp_ne(PG_FUNCTION_ARGS)
static int interval_cmp_internal(const Interval *interval1, const Interval *interval2)
Datum interval_recv(PG_FUNCTION_ARGS)
#define INTERVAL_TO_MICROSECONDS(i)
Datum statement_timestamp(PG_FUNCTION_ARGS)
Datum timestamptz_age(PG_FUNCTION_ARGS)
Datum interval_mul(PG_FUNCTION_ARGS)
Datum interval_div(PG_FUNCTION_ARGS)
Datum timestamptz_trunc_zone(PG_FUNCTION_ARGS)
Datum timestamp_eq_timestamptz(PG_FUNCTION_ARGS)
static TimestampTz timestamptz_pl_interval_internal(TimestampTz timestamp, Interval *span, pg_tz *attimezone)
static Datum generate_series_timestamptz_internal(FunctionCallInfo fcinfo)
int itm2interval(struct pg_itm *itm, Interval *span)
pg_time_t timestamptz_to_time_t(TimestampTz t)
Datum make_timestamp(PG_FUNCTION_ARGS)
Datum intervaltypmodout(PG_FUNCTION_ARGS)
static int interval_sign(const Interval *interval)
static void do_interval_discard(IntervalAggState *state, Interval *newval)
Datum timeofday(PG_FUNCTION_ARGS)
Datum generate_series_timestamptz_at_zone(PG_FUNCTION_ARGS)
int date2isoyear(int year, int mon, int mday)
Timestamp timestamptz2timestamp_safe(TimestampTz timestamp, Node *escontext)
Datum timestamp_izone(PG_FUNCTION_ARGS)
static Datum timestamp_decrement(Relation rel, Datum existing, bool *underflow)
static int parse_sane_timezone(struct pg_tm *tm, text *zone)
Datum timestamp_at_local(PG_FUNCTION_ARGS)
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Datum in_range_timestamptz_interval(PG_FUNCTION_ARGS)
Datum interval_avg_combine(PG_FUNCTION_ARGS)
Datum extract_interval(PG_FUNCTION_ARGS)
Datum timestamp_eq(PG_FUNCTION_ARGS)
#define TIMESTAMP_LT(t1, t2)
#define FLOAT8_FITS_IN_INT32(num)
#define Assert(condition)
#define FLOAT8_FITS_IN_INT64(num)
Node * estimate_expression_value(PlannerInfo *root, Node *node)
#define DATETIME_MIN_JULIAN
#define INTERVAL_NOEND(i)
#define MAX_TIMESTAMP_PRECISION
#define INTERVAL_NOT_FINITE(i)
#define TIMESTAMP_NOBEGIN(j)
#define TIMESTAMP_END_JULIAN
#define IS_VALID_JULIAN(y, m, d)
#define INTERVAL_NOBEGIN(i)
#define INTERVAL_IS_NOBEGIN(i)
#define IS_VALID_TIMESTAMP(t)
#define MAX_INTERVAL_PRECISION
#define INTERVAL_IS_NOEND(i)
#define TIMESTAMP_IS_NOEND(j)
#define TIMESTAMP_IS_NOBEGIN(j)
#define TIMESTAMP_NOT_FINITE(j)
#define POSTGRES_EPOCH_JDATE
#define TIMESTAMP_NOEND(j)
bool float_time_overflows(int hour, int min, double sec)
int errcode(int sqlerrcode)
#define ereturn(context, dummy_value,...)
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc0_object(type)
static float8 float8_mul(const float8 val1, const float8 val2)
static float8 get_float8_infinity(void)
#define PG_GETARG_BYTEA_PP(n)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_FLOAT8(n)
#define PG_RETURN_FLOAT8(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
char * format_type_be(Oid type_oid)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
#define SRF_RETURN_DONE(_funcctx)
Datum hashint8extended(PG_FUNCTION_ARGS)
Datum hashint8(PG_FUNCTION_ARGS)
#define DTERR_INTERVAL_OVERFLOW
#define TZNAME_FIXED_OFFSET
#define DTERR_TZDISP_OVERFLOW
#define DTERR_FIELD_OVERFLOW
static int int128_compare(INT128 x, INT128 y)
static INT128 int64_to_int128(int64 v)
static int64 int128_to_int64(INT128 val)
static void int128_add_int64_mul_int64(INT128 *i128, int64 x, int64 y)
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
static int timestamp2tm(timestamp dt, int *tzp, struct tm *tm, fsec_t *fsec, const char **tzn)
static timestamp SetEpochTimestamp(void)
int tm2timestamp(struct tm *tm, fsec_t fsec, int *tzp, timestamp *result)
char * pstrdup(const char *in)
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
int32 exprTypmod(const Node *expr)
Node * relabel_to_typmod(Node *expr, int32 typmod)
static bool is_funcclause(const void *clause)
#define IsA(nodeptr, _type_)
static Numeric DatumGetNumeric(Datum X)
#define PG_RETURN_NUMERIC(x)
static Datum NumericGetDatum(Numeric X)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static int list_length(const List *l)
static rewind_source * source
static char buf[DEFAULT_XLOG_SEG_SIZE]
bool pg_get_timezone_offset(const pg_tz *tz, long int *gmtoff)
PGDLLIMPORT pg_tz * session_timezone
size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm *t)
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
struct pg_tm * pg_gmtime(const pg_time_t *timep)
size_t strlcpy(char *dst, const char *src, size_t siz)
#define Int64GetDatumFast(X)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum X)
static Datum Float8GetDatum(float8 X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
unsigned int pq_getmsgint(StringInfo msg, int b)
void pq_getmsgend(StringInfo msg)
void pq_begintypsend(StringInfo buf)
int64 pq_getmsgint64(StringInfo msg)
bytea * pq_endtypsend(StringInfo buf)
static void pq_sendint32(StringInfo buf, uint32 i)
static void pq_sendint64(StringInfo buf, uint64 i)
char * psprintf(const char *fmt,...)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
struct SkipSupportData * SkipSupport
struct SortSupportData * SortSupport
struct StringInfoData * StringInfo
static void initReadOnlyStringInfo(StringInfo str, char *data, int len)
SkipSupportIncDec decrement
SkipSupportIncDec increment
int(* comparator)(Datum x, Datum y, SortSupport ssup)
int ssup_datum_signed_cmp(Datum x, Datum y, SortSupport ssup)
#define INTERVAL_FULL_RANGE
#define timestamptz_cmp_internal(dt1, dt2)
#define INTERVAL_PRECISION(t)
static Datum TimestampTzGetDatum(TimestampTz X)
#define INTERVAL_RANGE(t)
static Datum TimestampGetDatum(Timestamp X)
#define PG_GETARG_TIMESTAMP(n)
static Datum IntervalPGetDatum(const Interval *X)
#define PG_RETURN_TIMESTAMP(x)
#define PG_GETARG_INTERVAL_P(n)
#define PG_GETARG_TIMESTAMPTZ(n)
#define PG_RETURN_TIMESTAMPTZ(x)
static Interval * DatumGetIntervalP(Datum X)
#define PG_RETURN_INTERVAL_P(x)
#define INTERVAL_TYPMOD(p, r)
static Timestamp DatumGetTimestamp(Datum X)
#define INTERVAL_FULL_PRECISION
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
text * cstring_to_text(const char *s)
void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len)
static const unsigned __int64 epoch
int gettimeofday(struct timeval *tp, void *tzp)
TimestampTz GetCurrentStatementStartTimestamp(void)
TimestampTz GetCurrentTransactionStartTimestamp(void)