-- Stage J3 sweeps: the interval arithmetic, series and binning of jtimestamp, -- jtimestamptz and jdate checked against an independent oracle, over every -- hour of 2024 and of 2020, every month end of the leap years 1399 to 1412 and -- the common years between, and both range edges in five time zones. The -- hand-computed tables of jt_arith, jt_dst, jt_series and jt_bin say what the -- right answers are in chosen cases; this file says there is no case, in these -- grids, where the C code and the oracle part. -- -- The oracle uses no code under test. Its Jalali side is the real jdate type: -- jdate_part for the year, month and day, the text parser for the date of a month -- (the month length is 31, 30, or 29 and 30 when 12-30 parses, which is the -- leap rule of the jdate parser), the casts jdate <-> date for the Gregorian day. -- Its Gregorian side is core's own arithmetic on timestamp and timestamptz: -- AT TIME ZONE for the wall clock of a zone and its gap and overlap rule, -- interval '1 day' on a wall clock, date_bin for the bins, generate_series for the -- series without a month. A month step of the oracle is: the local date of the -- instant in the zone, the same date n Jalali months later with the day clamped to -- the month length, the same wall time, back to an instant by core. Nothing here -- calls jdate_add_months, the local-time helper, or the + operators of the new -- types except as the thing being tested. -- -- Every sweep prints counts and booleans only, so the output is the same on every -- server whatever its time zone data (the witnesses that a grid really contains a -- gap or an overlap are booleans). Errors are shown as SQLSTATE only. The file -- passes on correct code by design; the negative controls (section 6) show that -- the sweeps can fail: each feeds a deliberately wrong oracle and must report -- mismatches. The last section (7) is the volatility catalog of every function the -- stage added. SET DateStyle = 'ISO, YMD'; SET IntervalStyle = 'postgres'; SET timezone = 'UTC'; \set VERBOSITY sqlstate -- --------------------------------------------------------------------- -- The oracle -- --------------------------------------------------------------------- -- text of a Jalali date CREATE FUNCTION pg_temp.ymd(y int, m int, d int) RETURNS text LANGUAGE sql IMMUTABLE AS $$ SELECT CASE WHEN y < 0 THEN '-' ELSE '' END || lpad(abs(y)::text, 4, '0') || '-' || lpad(m::text, 2, '0') || '-' || lpad(d::text, 2, '0') $$; -- month length: 31 for months 1 to 6, 30 for 7 to 11, and for Esfand 29, or 30 when -- the jdate parser accepts the 30th (it is the leap test of the type) CREATE FUNCTION pg_temp.mlen(y int, m int) RETURNS int LANGUAGE sql IMMUTABLE AS $$ SELECT CASE WHEN m <= 6 THEN 31 WHEN m <= 11 THEN 30 ELSE 29 + pg_input_is_valid(pg_temp.ymd(y, 12, 30), 'jdate')::int END $$; -- months counted from year 0 month 1, and back (floor division, so negative -- counts work); n months after d is the month t of this count CREATE FUNCTION pg_temp.tmonths(d jdate, n int) RETURNS int LANGUAGE sql IMMUTABLE AS $$ SELECT jdate_part('year', d)::int * 12 + jdate_part('month', d)::int - 1 + n $$; CREATE FUNCTION pg_temp.ty(t int) RETURNS int LANGUAGE sql IMMUTABLE AS $$ SELECT (t - ((t % 12) + 12) % 12) / 12 $$; CREATE FUNCTION pg_temp.tm(t int) RETURNS int LANGUAGE sql IMMUTABLE AS $$ SELECT ((t % 12) + 12) % 12 + 1 $$; -- n Jalali months after d, the day clamped to the length of the target month; -- NULL when the target year is outside -61 .. 3177 CREATE FUNCTION pg_temp.oadd(d jdate, n int) RETURNS jdate LANGUAGE sql IMMUTABLE AS $$ SELECT CASE WHEN pg_temp.ty(pg_temp.tmonths(d, n)) BETWEEN -61 AND 3177 THEN pg_temp.ymd(pg_temp.ty(pg_temp.tmonths(d, n)), pg_temp.tm(pg_temp.tmonths(d, n)), least(jdate_part('day', d)::int, pg_temp.mlen(pg_temp.ty(pg_temp.tmonths(d, n)), pg_temp.tm(pg_temp.tmonths(d, n)))))::jdate END $$; -- the oracle against the report's 15-row table (computed there by hand): 15 of 15 SELECT count(*) AS rows, count(*) FILTER (WHERE pg_temp.oadd(s::jdate, n)::text IS NOT DISTINCT FROM e) AS oracle_matches_report FROM (VALUES ('1403-06-31', 1, '1403-07-30'), ('1403-06-31', 6, '1403-12-30'), ('1403-07-30', -1, '1403-06-30'), ('1403-12-30', 12, '1404-12-29'), ('1403-12-30', 60, '1408-12-30'), ('1403-12-30', -12, '1402-12-29'), ('1403-12-30', -60, '1398-12-29'), ('1403-11-30', 1, '1403-12-30'), ('1404-11-30', 1, '1404-12-29'), ('1403-01-31', 11, '1403-12-30'), ('1403-01-31', 12, '1404-01-31'), ('0000-01-31', -1, '-0001-12-29'), ('0001-01-30', -1, '0000-12-30'), ('3177-12-29', -1, '3177-11-29'), ('3177-12-29', 1, NULL)) v(s, n, e); -- the leap years of the jdate parser in 1398 to 1413, and the month lengths: the -- last day of a month is followed by the first day of the next one SELECT string_agg(y::text, ' ' ORDER BY y) AS leap_years_1398_1413 FROM generate_series(1398, 1413) y WHERE pg_temp.mlen(y, 12) = 30; SELECT count(*) AS month_ends, count(*) FILTER (WHERE pg_temp.ymd(y, m, pg_temp.mlen(y, m))::jdate + 1 = pg_temp.ymd(y + m / 12, m % 12 + 1, 1)::jdate) AS followed_by_next_first FROM generate_series(1380, 1430) y, generate_series(1, 12) m; SELECT count(*) AS years, count(*) FILTER (WHERE pg_temp.ymd(y + 1, 1, 1)::jdate - pg_temp.ymd(y, 1, 1)::jdate = 365 + (pg_temp.mlen(y, 12) - 29)) AS year_lengths_agree FROM generate_series(1380, 1430) y; -- the oracle table of month steps for the local dates the grids reach: the -- Gregorian date, the step in Jalali months (1, -1, 12, -12), and the Gregorian -- date that many months later. It covers 2015-12 to 2027-12, so the hours of 2020 -- and 2024 and the series that start in them and run a year or two past them in -- either direction. CREATE TEMP TABLE sw_dmap AS SELECT d::date AS d, n, pg_temp.oadd(d::date::jdate, n)::date AS nd FROM generate_series(date '2015-12-01', date '2027-12-31', interval '1 day') days(d), (VALUES (1), (-1), (12), (-12)) v(n); CREATE UNIQUE INDEX ON sw_dmap (d, n); ANALYZE sw_dmap; SELECT count(*) AS oracle_rows, count(*) FILTER (WHERE nd IS NULL) AS without_target FROM sw_dmap; -- "ERR " or the text of the single value of a query CREATE FUNCTION pg_temp.show(q text) RETURNS text LANGUAGE plpgsql AS $f$ DECLARE r text; BEGIN EXECUTE q INTO r; RETURN coalesce(r, 'NULL'); EXCEPTION WHEN OTHERS THEN RETURN 'ERR ' || SQLSTATE; END $f$; -- the same under a time zone (set for the one statement, UTC afterwards) CREATE FUNCTION pg_temp.show_in(zone text, q text) RETURNS text LANGUAGE plpgsql AS $f$ DECLARE r text; BEGIN PERFORM set_config('TimeZone', zone, false); r := pg_temp.show(q); PERFORM set_config('TimeZone', 'UTC', false); RETURN r; END $f$; -- --------------------------------------------------------------------- -- 1. Every hour of 2024 and of 2020: jtimestamptz + '1 day', - '1 day', -- + '1 month' and - '1 month' in Asia/Tehran, Europe/Paris and Asia/Kathmandu, -- each against the oracle in the same zone. The grids are the hourly UTC -- instants (8784 each, both years are leap years). The oracle takes the wall -- clock by core's AT TIME ZONE, adds one day by core's wall clock arithmetic -- or one Jalali month by the oracle table, and goes back to an instant by core's -- AT TIME ZONE (a wall time in a gap moves forward, an ambiguous one is the -- second occurrence). The witnesses say the grid reaches a gap (a step lands on -- a wall time that does not exist) and an overlap (it lands on one that occurs -- twice), for the day step and for the month step: Paris in 2024 and 2020 and -- Tehran in 2020 have both (Tehran gave up daylight saving time in 2022), Kathmandu -- neither. -- --------------------------------------------------------------------- CREATE TEMP TABLE sw_h2024 AS SELECT g.t FROM generate_series(timestamptz '2024-01-01 00:00+00', timestamptz '2024-12-31 23:00+00', interval '1 hour') g(t); CREATE TEMP TABLE sw_h2020 AS SELECT g.t FROM generate_series(timestamptz '2020-01-01 00:00+00', timestamptz '2020-12-31 23:00+00', interval '1 hour') g(t); SELECT (SELECT count(*) FROM sw_h2024) AS hours_2024, (SELECT count(*) FROM sw_h2020) AS hours_2020; -- skew shifts every oracle instant (zero in the sweeps, not zero in a control) CREATE FUNCTION pg_temp.sweep_hours(z text, grid regclass, skew interval DEFAULT '0') RETURNS TABLE (hours bigint, plus_day bigint, minus_day bigint, plus_month bigint, minus_month bigint, gap_day boolean, overlap_day boolean, gap_month boolean, overlap_month boolean) LANGUAGE plpgsql AS $f$ BEGIN PERFORM set_config('TimeZone', z, false); RETURN QUERY EXECUTE format($q$ WITH j AS ( SELECT w.t, w.loc, w.t::jtimestamptz AS jt, w.loc::time AS tod, p.nd AS nplus, m.nd AS nminus FROM (SELECT g.t, g.t AT TIME ZONE %1$L AS loc FROM %2$s g) w JOIN sw_dmap p ON p.d = w.loc::date AND p.n = 1 JOIN sw_dmap m ON m.d = w.loc::date AND m.n = -1 ) SELECT count(*), count(*) FILTER (WHERE (j.jt + interval '1 day')::timestamptz IS DISTINCT FROM ((j.loc + interval '1 day') AT TIME ZONE %1$L) + %3$L::interval), count(*) FILTER (WHERE (j.jt - interval '1 day')::timestamptz IS DISTINCT FROM ((j.loc - interval '1 day') AT TIME ZONE %1$L) + %3$L::interval), count(*) FILTER (WHERE (j.jt + interval '1 month')::timestamptz IS DISTINCT FROM ((j.nplus + j.tod) AT TIME ZONE %1$L) + %3$L::interval), count(*) FILTER (WHERE (j.jt - interval '1 month')::timestamptz IS DISTINCT FROM ((j.nminus + j.tod) AT TIME ZONE %1$L) + %3$L::interval), -- the day step landed on a wall time that does not exist count(*) FILTER (WHERE ((j.loc + interval '1 day') AT TIME ZONE %1$L) AT TIME ZONE %1$L <> j.loc + interval '1 day') > 0, -- ... or on one that occurs twice (the hour before has the same wall time) count(*) FILTER (WHERE (((j.loc + interval '1 day') AT TIME ZONE %1$L) - interval '1 hour') AT TIME ZONE %1$L = j.loc + interval '1 day') > 0, -- the same two for the wall time the month step lands on (+1 month) count(*) FILTER (WHERE ((j.nplus + j.tod) AT TIME ZONE %1$L) AT TIME ZONE %1$L <> j.nplus + j.tod) > 0, count(*) FILTER (WHERE (((j.nplus + j.tod) AT TIME ZONE %1$L) - interval '1 hour') AT TIME ZONE %1$L = j.nplus + j.tod) > 0 FROM j $q$, z, grid, skew); PERFORM set_config('TimeZone', 'UTC', false); END $f$; SELECT 'Asia/Tehran 2024' AS grid, * FROM pg_temp.sweep_hours('Asia/Tehran', 'sw_h2024'); SELECT 'Europe/Paris 2024' AS grid, * FROM pg_temp.sweep_hours('Europe/Paris', 'sw_h2024'); SELECT 'Asia/Kathmandu 2024' AS grid, * FROM pg_temp.sweep_hours('Asia/Kathmandu', 'sw_h2024'); SELECT 'Asia/Tehran 2020' AS grid, * FROM pg_temp.sweep_hours('Asia/Tehran', 'sw_h2020'); SELECT 'Europe/Paris 2020' AS grid, * FROM pg_temp.sweep_hours('Europe/Paris', 'sw_h2020'); SELECT 'Asia/Kathmandu 2020' AS grid, * FROM pg_temp.sweep_hours('Asia/Kathmandu', 'sw_h2020'); -- the same hours as jtimestamp wall clocks (no zone, so no gaps), in UTC, and the -- days of both years as jdate with a one month, one day and one year step CREATE FUNCTION pg_temp.sweep_hours_ts(grid regclass) RETURNS TABLE (hours bigint, plus_day bigint, minus_day bigint, plus_month bigint, minus_month bigint, plus_year bigint, minus_year bigint) LANGUAGE plpgsql AS $f$ BEGIN RETURN QUERY EXECUTE format($q$ WITH j AS ( SELECT w.loc, w.loc::jtimestamp AS jt, w.loc::time AS tod, p.nd AS nplus, m.nd AS nminus, py.nd AS nyplus, my.nd AS nyminus FROM (SELECT g.t AT TIME ZONE 'UTC' AS loc FROM %s g) w JOIN sw_dmap p ON p.d = w.loc::date AND p.n = 1 JOIN sw_dmap m ON m.d = w.loc::date AND m.n = -1 JOIN sw_dmap py ON py.d = w.loc::date AND py.n = 12 JOIN sw_dmap my ON my.d = w.loc::date AND my.n = -12 ) SELECT count(*), count(*) FILTER (WHERE (j.jt + interval '1 day')::timestamp IS DISTINCT FROM j.loc + interval '1 day'), count(*) FILTER (WHERE (j.jt - interval '1 day')::timestamp IS DISTINCT FROM j.loc - interval '1 day'), count(*) FILTER (WHERE (j.jt + interval '1 month')::timestamp IS DISTINCT FROM j.nplus + j.tod), count(*) FILTER (WHERE (j.jt - interval '1 month')::timestamp IS DISTINCT FROM j.nminus + j.tod), count(*) FILTER (WHERE (j.jt + interval '1 year')::timestamp IS DISTINCT FROM j.nyplus + j.tod), count(*) FILTER (WHERE (j.jt - interval '1 year')::timestamp IS DISTINCT FROM j.nyminus + j.tod) FROM j $q$, grid); END $f$; SELECT 'jtimestamp 2024' AS grid, * FROM pg_temp.sweep_hours_ts('sw_h2024'); SELECT 'jtimestamp 2020' AS grid, * FROM pg_temp.sweep_hours_ts('sw_h2020'); -- jdate + interval returns the jtimestamp of the midnight; every local day SELECT count(DISTINCT d) AS days, count(*) FILTER (WHERE (d::jdate + interval '1 day')::timestamp IS DISTINCT FROM (d + 1)::timestamp OR (d::jdate - interval '1 day')::timestamp IS DISTINCT FROM (d - 1)::timestamp) AS day_mismatches, count(*) FILTER (WHERE n IN (1, -1) AND (d::jdate + make_interval(months => n))::timestamp IS DISTINCT FROM nd::timestamp) AS plus_month_mismatches, count(*) FILTER (WHERE n IN (1, -1) AND (d::jdate - make_interval(months => -n))::timestamp IS DISTINCT FROM nd::timestamp) AS minus_month_mismatches, count(*) FILTER (WHERE n IN (12, -12) AND (d::jdate + make_interval(years => n / 12))::timestamp IS DISTINCT FROM nd::timestamp) AS year_mismatches FROM sw_dmap WHERE d BETWEEN date '2023-12-31' AND date '2025-01-01' OR d BETWEEN date '2019-12-31' AND date '2021-01-01'; -- --------------------------------------------------------------------- -- 2. Every month end of the leap years 1399, 1403, 1408, 1412 and of the common -- years between (1399 to 1412), plus the 30th of the months that have 31 days -- (the other day that is clamped): + n months for n from -48 to 48 and -- + n years for n from -16 to 16, with the - operator on the negated step, for -- jtimestamp, jdate and jtimestamptz in UTC and in Asia/Tehran, each against the -- oracle. -- --------------------------------------------------------------------- CREATE TEMP TABLE sw_ends AS SELECT y, m, d, pg_temp.ymd(y, m, d)::jdate AS jd FROM generate_series(1399, 1412) y, generate_series(1, 12) m, LATERAL (SELECT pg_temp.mlen(y, m) AS d UNION SELECT 30 WHERE pg_temp.mlen(y, m) = 31) dd(d); SELECT count(*) AS start_days, count(*) FILTER (WHERE d = pg_temp.mlen(y, m)) AS month_ends, count(*) FILTER (WHERE y IN (1399, 1403, 1408, 1412) AND m = 12 AND d = 30) AS leap_esfand_30 FROM sw_ends; CREATE TEMP TABLE sw_steps AS SELECT s.jd, k.unit, k.n, pg_temp.oadd(s.jd, CASE k.unit WHEN 'month' THEN k.n ELSE 12 * k.n END) AS want FROM sw_ends s, (SELECT 'month' AS unit, n FROM generate_series(-48, 48) n UNION ALL SELECT 'year', n FROM generate_series(-16, 16) n) k; ANALYZE sw_steps; SELECT unit, count(*) AS cases, count(*) FILTER (WHERE want IS NULL) AS outside_range, count(*) FILTER (WHERE want IS NOT NULL AND jdate_part('day', want) < jdate_part('day', jd)) AS clamped FROM sw_steps GROUP BY unit ORDER BY unit; -- jtimestamp: start at 13:45:30.123456, + the step and - the negated step SELECT unit, count(*) AS cases, count(*) FILTER (WHERE ((jd::text || ' 13:45:30.123456')::jtimestamp + CASE unit WHEN 'month' THEN make_interval(months => n) ELSE make_interval(years => n) END)::timestamp IS DISTINCT FROM want::date + time '13:45:30.123456') AS plus_mismatches, count(*) FILTER (WHERE ((jd::text || ' 13:45:30.123456')::jtimestamp - CASE unit WHEN 'month' THEN make_interval(months => -n) ELSE make_interval(years => -n) END)::timestamp IS DISTINCT FROM want::date + time '13:45:30.123456') AS minus_mismatches FROM sw_steps GROUP BY unit ORDER BY unit; -- jdate: the result is the jtimestamp of the midnight SELECT unit, count(*) AS cases, count(*) FILTER (WHERE (jd + CASE unit WHEN 'month' THEN make_interval(months => n) ELSE make_interval(years => n) END)::timestamp IS DISTINCT FROM want::date::timestamp) AS plus_mismatches, count(*) FILTER (WHERE (jd - CASE unit WHEN 'month' THEN make_interval(months => -n) ELSE make_interval(years => -n) END)::timestamp IS DISTINCT FROM want::date::timestamp) AS minus_mismatches FROM sw_steps GROUP BY unit ORDER BY unit; -- jtimestamptz at 13:45:30.123456 local time of the zone CREATE FUNCTION pg_temp.sweep_ends_tz(z text) RETURNS TABLE (unit text, cases bigint, plus_mismatches bigint, minus_mismatches bigint) LANGUAGE plpgsql AS $f$ BEGIN PERFORM set_config('TimeZone', z, false); RETURN QUERY WITH j AS ( SELECT s.unit, s.n, s.want, ((s.jd::date + time '13:45:30.123456') AT TIME ZONE z)::jtimestamptz AS st FROM sw_steps s ) SELECT j.unit, count(*), count(*) FILTER (WHERE (j.st + CASE j.unit WHEN 'month' THEN make_interval(months => j.n) ELSE make_interval(years => j.n) END)::timestamptz IS DISTINCT FROM ((j.want::date + time '13:45:30.123456') AT TIME ZONE z)), count(*) FILTER (WHERE (j.st - CASE j.unit WHEN 'month' THEN make_interval(months => -j.n) ELSE make_interval(years => -j.n) END)::timestamptz IS DISTINCT FROM ((j.want::date + time '13:45:30.123456') AT TIME ZONE z)) FROM j GROUP BY j.unit ORDER BY j.unit; PERFORM set_config('TimeZone', 'UTC', false); END $f$; SELECT 'UTC' AS zone, * FROM pg_temp.sweep_ends_tz('UTC'); SELECT 'Asia/Tehran' AS zone, * FROM pg_temp.sweep_ends_tz('Asia/Tehran'); -- --------------------------------------------------------------------- -- 3. The range edges. jtimestamptz has a safe range, from 16 hours after the start -- of the first day (-0061-01-01) to 16 hours before the end of the last -- (3177-12-29), so every stored instant prints in a zone up to +/-15:59. The -- bounds come from the real jdate cast and core's arithmetic. Instants every -- half hour for the first two days from each edge, every hour to the fourth -- day, every six hours to the 45th day (the month steps change their answer at -- about a month), the last valid instant included: each plus and minus one day, -- one hour, one month, one month and one day, in the zones UTC, +14, -11, -- +15:59 and -15:59 (POSIX names: fixed offsets, no tzdata in the answer). -- The oracle says what the result would be in core's wide range; the answer is -- an error (22008) when that is outside the safe range or the month step leaves -- the Jalali years, else the same instant. -- --------------------------------------------------------------------- CREATE TEMP TABLE sw_bounds AS SELECT ('-0061-01-01'::jdate)::date AS d0, ('3177-12-29'::jdate)::date AS d1, (('-0061-01-01'::jdate)::date + time '16:00') AT TIME ZONE 'UTC' AS lo, (('3177-12-29'::jdate)::date + time '08:00') AT TIME ZONE 'UTC' AS hi; CREATE TEMP TABLE sw_egrid AS SELECT 'lower'::text AS edge, b.lo + k * interval '30 minutes' AS t FROM sw_bounds b, generate_series(0, 95) k UNION ALL SELECT 'lower', b.lo + k * interval '1 hour' FROM sw_bounds b, generate_series(48, 96) k UNION ALL SELECT 'lower', b.lo + k * interval '6 hours' FROM sw_bounds b, generate_series(17, 180) k UNION ALL SELECT 'upper', b.hi - interval '1 microsecond' FROM sw_bounds b UNION ALL SELECT 'upper', b.hi - k * interval '30 minutes' FROM sw_bounds b, generate_series(1, 96) k UNION ALL SELECT 'upper', b.hi - k * interval '1 hour' FROM sw_bounds b, generate_series(49, 96) k UNION ALL SELECT 'upper', b.hi - k * interval '6 hours' FROM sw_bounds b, generate_series(17, 180) k; SELECT edge, count(*) AS instants FROM sw_egrid GROUP BY edge ORDER BY edge; -- the oracle table of month steps for the local dates near the edges CREATE TEMP TABLE sw_edmap AS SELECT d::date AS d, n, pg_temp.oadd(d::date::jdate, n)::date AS nd FROM (SELECT g FROM sw_bounds b, generate_series(b.d0, b.d0 + 50, interval '1 day') g UNION ALL SELECT g FROM sw_bounds b, generate_series(b.d1 - 50, b.d1, interval '1 day') g) days(d), (VALUES (1), (-1)) v(n); CREATE UNIQUE INDEX ON sw_edmap (d, n); ANALYZE sw_edmap; -- the steps: label, interval, sign of the operator, month step, day step (both -- signed as applied), time step CREATE TEMP TABLE sw_ops (label text, iv interval, sgn int, mo int, dy int, tm interval); INSERT INTO sw_ops VALUES ('+1 day', '1 day', 1, 0, 1, '0'), ('-1 day', '1 day', -1, 0, -1, '0'), ('+1 hour', '1 hour', 1, 0, 0, '1 hour'), ('-1 hour', '1 hour', -1, 0, 0, '-1 hour'), ('+1 month', '1 month', 1, 1, 0, '0'), ('-1 month', '1 month', -1, -1, 0, '0'), ('+1 month 1 day', '1 month 1 day', 1, 1, 1, '0'), ('-1 month 1 day', '1 month 1 day', -1, -1, -1, '0'); -- the instant or the SQLSTATE of t + iv or t - iv CREATE FUNCTION pg_temp.try_tz(t jtimestamptz, iv interval, sgn int, OUT r timestamptz, OUT st text) LANGUAGE plpgsql AS $f$ BEGIN IF sgn > 0 THEN r := (t + iv)::timestamptz; ELSE r := (t - iv)::timestamptz; END IF; EXCEPTION WHEN OTHERS THEN r := NULL; st := SQLSTATE; END $f$; -- adj shifts both bounds of the oracle (zero in the sweeps, not zero in the control) CREATE FUNCTION pg_temp.sweep_edges(z text, adj interval DEFAULT '0') RETURNS TABLE (edge text, cases bigint, inside bigint, outside bigint, unmapped bigint, mismatches bigint) LANGUAGE plpgsql AS $f$ BEGIN PERFORM set_config('TimeZone', z, false); RETURN QUERY WITH j AS ( SELECT g.edge, g.t::jtimestamptz AS jt, g.t AS t, o.*, g.t AT TIME ZONE z AS loc FROM sw_egrid g CROSS JOIN sw_ops o ), w AS ( SELECT j.*, m.d IS NULL AND j.mo <> 0 AS nomap, CASE WHEN j.mo = 0 THEN j.loc::date ELSE m.nd END AS nd FROM j LEFT JOIN sw_edmap m ON m.d = j.loc::date AND m.n = j.mo ), x AS ( SELECT w.edge, w.nomap, (((w.nd + w.loc::time) + w.dy * interval '1 day') AT TIME ZONE z) + w.tm AS want, a.r, a.st FROM w CROSS JOIN LATERAL pg_temp.try_tz(w.jt, w.iv, w.sgn) a ), y AS ( SELECT x.*, x.want IS NOT NULL AND x.want >= b.lo + adj AND x.want < b.hi + adj AS inside FROM x, sw_bounds b ) SELECT y.edge, count(*), count(*) FILTER (WHERE y.inside), count(*) FILTER (WHERE NOT y.inside), count(*) FILTER (WHERE y.nomap), count(*) FILTER (WHERE CASE WHEN y.inside THEN y.st IS NOT NULL OR y.r <> y.want ELSE y.st IS DISTINCT FROM '22008' END) FROM y GROUP BY y.edge ORDER BY y.edge; PERFORM set_config('TimeZone', 'UTC', false); END $f$; SELECT 'UTC' AS zone, * FROM pg_temp.sweep_edges('UTC'); SELECT '+14' AS zone, * FROM pg_temp.sweep_edges('<+14>-14'); SELECT '-11' AS zone, * FROM pg_temp.sweep_edges('<-11>11'); SELECT '+15:59' AS zone, * FROM pg_temp.sweep_edges('<+15:59>-15:59'); SELECT '-15:59' AS zone, * FROM pg_temp.sweep_edges('<-15:59>15:59'); -- the edge values themselves, computed by hand: UTC, and +15:59 where the last -- valid instant is 23:58:59.999999 local (08:00 UTC less a microsecond) SELECT label, pg_temp.show_in(zone, stmt) AS result FROM (VALUES (1, 'first valid', 'UTC', $$SELECT '-0061-01-01 16:00:00+00'::jtimestamptz$$), (2, 'first - 1 hour', 'UTC', $$SELECT '-0061-01-01 16:00:00+00'::jtimestamptz - interval '1 hour'$$), (3, 'first + 1 day', 'UTC', $$SELECT '-0061-01-01 16:00:00+00'::jtimestamptz + interval '1 day'$$), (4, 'first + 1 month', 'UTC', $$SELECT '-0061-01-01 16:00:00+00'::jtimestamptz + interval '1 month'$$), (5, 'first - 1 month', 'UTC', $$SELECT '-0061-01-01 16:00:00+00'::jtimestamptz - interval '1 month'$$), (6, 'last valid', 'UTC', $$SELECT '3177-12-29 07:59:59.999999+00'::jtimestamptz$$), (7, 'last + 1 microsecond', 'UTC', $$SELECT '3177-12-29 07:59:59.999999+00'::jtimestamptz + interval '1 microsecond'$$), (8, 'last - 1 day', 'UTC', $$SELECT '3177-12-29 07:59:59.999999+00'::jtimestamptz - interval '1 day'$$), (9, 'last - 1 month', 'UTC', $$SELECT '3177-12-29 07:59:59.999999+00'::jtimestamptz - interval '1 month'$$), (10, 'last + 1 month', 'UTC', $$SELECT '3177-12-29 07:59:59.999999+00'::jtimestamptz + interval '1 month'$$), (11, 'last valid at +15:59', '<+15:59>-15:59', $$SELECT '3177-12-29 23:58:59.999999+15:59'::jtimestamptz$$), (12, 'last + 1 microsecond at +15:59', '<+15:59>-15:59', $$SELECT '3177-12-29 23:58:59.999999+15:59'::jtimestamptz + interval '1 microsecond'$$), (13, 'last - 1 day at +15:59', '<+15:59>-15:59', $$SELECT '3177-12-29 23:58:59.999999+15:59'::jtimestamptz - interval '1 day'$$) ) v(ord, label, zone, stmt) ORDER BY ord; -- jtimestamp (no zone): the range is the whole of the first and the last day CREATE TEMP TABLE sw_egrid_ts AS SELECT g.edge, CASE g.edge WHEN 'lower' THEN b.d0::timestamp + (g.t - b.lo) ELSE (b.d1 + 1)::timestamp + (g.t - b.hi) END AS t FROM sw_egrid g, sw_bounds b; CREATE FUNCTION pg_temp.try_ts(t jtimestamp, iv interval, sgn int, OUT r timestamp, OUT st text) LANGUAGE plpgsql AS $f$ BEGIN IF sgn > 0 THEN r := (t + iv)::timestamp; ELSE r := (t - iv)::timestamp; END IF; EXCEPTION WHEN OTHERS THEN r := NULL; st := SQLSTATE; END $f$; WITH j AS ( SELECT g.edge, g.t AS loc, g.t::jtimestamp AS jt, o.* FROM sw_egrid_ts g CROSS JOIN sw_ops o ), w AS ( SELECT j.*, m.d IS NULL AND j.mo <> 0 AS nomap, CASE WHEN j.mo = 0 THEN j.loc::date ELSE m.nd END AS nd FROM j LEFT JOIN sw_edmap m ON m.d = j.loc::date AND m.n = j.mo ), x AS ( SELECT w.edge, w.nomap, ((w.nd + w.loc::time) + w.dy * interval '1 day') + w.tm AS want, a.r, a.st FROM w CROSS JOIN LATERAL pg_temp.try_ts(w.jt, w.iv, w.sgn) a ), y AS ( SELECT x.*, x.want IS NOT NULL AND x.want >= b.d0::timestamp AND x.want < (b.d1 + 1)::timestamp AS inside FROM x, sw_bounds b ) SELECT 'jtimestamp' AS type, y.edge, count(*) AS cases, count(*) FILTER (WHERE y.inside) AS inside, count(*) FILTER (WHERE NOT y.inside) AS outside, count(*) FILTER (WHERE y.nomap) AS unmapped, count(*) FILTER (WHERE CASE WHEN y.inside THEN y.st IS NOT NULL OR y.r <> y.want ELSE y.st IS DISTINCT FROM '22008' END) AS mismatches FROM y GROUP BY y.edge ORDER BY y.edge; -- --------------------------------------------------------------------- -- 4. Series over the same days. jgenerate_series against core's generate_series -- wherever the step has no month part (the same instants, so the same wall -- clock across a daylight saving change), and against the oracle where it has: -- element n + 1 is element n moved by the oracle table (the clamp sticks), back -- to an instant by core for jtimestamptz. -- --------------------------------------------------------------------- -- the oracle series, jtimestamp: from st while the element has not passed fin CREATE FUNCTION pg_temp.oseries_ts(st timestamp, fin timestamp, step int) RETURNS timestamp[] LANGUAGE plpgsql AS $f$ DECLARE r timestamp[] := '{}'; cur timestamp := st; nd date; BEGIN WHILE (step > 0 AND cur <= fin) OR (step < 0 AND cur >= fin) LOOP r := r || cur; SELECT m.nd INTO nd FROM sw_dmap m WHERE m.d = cur::date AND m.n = step; IF nd IS NULL THEN RAISE EXCEPTION 'no oracle row'; END IF; cur := nd + cur::time; IF cardinality(r) > 1000 THEN RAISE EXCEPTION 'runaway'; END IF; END LOOP; RETURN r; END $f$; -- ... and jtimestamptz in zone z: the step on the wall clock, back through core CREATE FUNCTION pg_temp.oseries_tz(st timestamptz, fin timestamptz, step int, z text) RETURNS timestamptz[] LANGUAGE plpgsql AS $f$ DECLARE r timestamptz[] := '{}'; cur timestamptz := st; loc timestamp; nd date; BEGIN WHILE (step > 0 AND cur <= fin) OR (step < 0 AND cur >= fin) LOOP r := r || cur; loc := cur AT TIME ZONE z; SELECT m.nd INTO nd FROM sw_dmap m WHERE m.d = loc::date AND m.n = step; IF nd IS NULL THEN RAISE EXCEPTION 'no oracle row'; END IF; cur := (nd + loc::time) AT TIME ZONE z; IF cardinality(r) > 1000 THEN RAISE EXCEPTION 'runaway'; END IF; END LOOP; RETURN r; END $f$; -- 4a. jtimestamptz in zone z, starting every day of the year at wall time tm: the -- series of one month and of one year, forwards and backwards, against the oracle; -- then the series of one day and of seven days starting at every hour of the first -- day, and of one hour from the first hour, to the end of the year, against core's -- generate_series; and the form with the zone argument against the form that reads -- the session zone CREATE FUNCTION pg_temp.sweep_series_tz(z text, y0 date, tm time) RETURNS TABLE (check_name text, series bigint, elements bigint, mismatches bigint) LANGUAGE plpgsql AS $f$ DECLARE t0 timestamptz := y0::timestamp AT TIME ZONE 'UTC'; fin timestamptz := (y0 + 365 + 0)::timestamp AT TIME ZONE 'UTC' + interval '23 hours'; BEGIN PERFORM set_config('TimeZone', z, false); RETURN QUERY SELECT v.name, count(*), sum(cardinality(q.b)), count(*) FILTER (WHERE q.a IS DISTINCT FROM q.b) FROM (VALUES ('month step', 1, 470), ('minus one month', -1, -400), ('year step', 12, 800), ('minus one year', -12, -800)) v(name, step, span), LATERAL ( SELECT ARRAY(SELECT g::timestamptz FROM jgenerate_series(s.st::jtimestamptz, (((y0 + v.span)::timestamp) AT TIME ZONE z)::jtimestamptz, make_interval(months => v.step)) g) AS a, pg_temp.oseries_tz(s.st, ((y0 + v.span)::timestamp) AT TIME ZONE z, v.step, z) AS b FROM (SELECT ((y0 + i) + tm) AT TIME ZONE z AS st FROM generate_series(0, 365) i) s) q GROUP BY v.name ORDER BY v.name COLLATE "C"; RETURN QUERY SELECT 'day, week and hour steps'::text, count(*), sum(cardinality(q.b)), count(*) FILTER (WHERE q.a IS DISTINCT FROM q.b OR q.c IS DISTINCT FROM q.b) FROM (SELECT t0 + h * interval '1 hour' AS st, step FROM generate_series(0, 23) h, (VALUES (interval '1 day'), (interval '7 days')) v(step) UNION ALL SELECT t0, interval '1 hour') s, LATERAL ( SELECT ARRAY(SELECT g::timestamptz FROM jgenerate_series(s.st::jtimestamptz, fin::jtimestamptz, s.step) g) AS a, ARRAY(SELECT g FROM generate_series(s.st, fin, s.step) g) AS b, ARRAY(SELECT g::timestamptz FROM jgenerate_series(s.st::jtimestamptz, fin::jtimestamptz, s.step, z) g) AS c) q; PERFORM set_config('TimeZone', 'UTC', false); END $f$; SELECT 'Europe/Paris 2024' AS grid, * FROM pg_temp.sweep_series_tz('Europe/Paris', date '2024-01-01', time '02:30'); SELECT 'Asia/Tehran 2020' AS grid, * FROM pg_temp.sweep_series_tz('Asia/Tehran', date '2020-01-01', time '00:30'); SELECT 'Asia/Kathmandu 2024' AS grid, * FROM pg_temp.sweep_series_tz('Asia/Kathmandu', date '2024-01-01', time '02:30'); -- 4b. jtimestamp and jdate series, starting every day of 2024 at 13:45:30.123456 (jdate: -- at midnight) WITH s AS ( SELECT d::date AS d FROM generate_series(date '2024-01-01', date '2024-12-31', interval '1 day') d ), q AS ( SELECT st.step, st.fin, ARRAY(SELECT g::timestamp FROM jgenerate_series((s.d + time '13:45:30.123456')::jtimestamp, st.fin::jtimestamp, make_interval(months => st.step)) g) AS a, pg_temp.oseries_ts(s.d + time '13:45:30.123456', st.fin, st.step) AS b, ARRAY(SELECT g::timestamp FROM jgenerate_series(s.d::jdate, st.fin::date::jdate, make_interval(months => st.step)) g) AS c, pg_temp.oseries_ts(s.d::timestamp, st.fin::date::timestamp, st.step) AS e FROM s, (VALUES (1, timestamp '2025-04-15 00:00'), (-1, timestamp '2022-12-01 00:00'), (12, timestamp '2027-01-01 00:00'), (-12, timestamp '2021-01-01 00:00')) st(step, fin) ) SELECT step AS months_step, count(*) AS series, sum(cardinality(b)) AS elements, count(*) FILTER (WHERE a IS DISTINCT FROM b) AS jtimestamp_mismatches, count(*) FILTER (WHERE c IS DISTINCT FROM e) AS jdate_interval_mismatches FROM q GROUP BY step ORDER BY step; -- jtimestamp without a month against core's generate_series on the same numbers SELECT count(*) AS series, sum(cardinality(b)) AS elements, count(*) FILTER (WHERE a IS DISTINCT FROM b) AS mismatches FROM (SELECT ARRAY(SELECT g::timestamp FROM jgenerate_series(s.st::jtimestamp, timestamp '2024-12-31 23:00'::jtimestamp, v.step) g) AS a, ARRAY(SELECT g FROM generate_series(s.st, timestamp '2024-12-31 23:00', v.step) g) AS b FROM (SELECT timestamp '2024-01-01 00:00' + h * interval '1 hour' AS st FROM generate_series(0, 23) h) s, (VALUES (interval '1 day'), (interval '7 days'), (interval '1 hour'), (interval '36 hours'), (interval '1 day 1 minute')) v(step)) q; -- jgenerate_series(jdate, jdate, int): the days, steps 1, 7, 31 and 45 forward and -- backward, against Gregorian day arithmetic on the same dates SELECT k AS step, count(*) AS series, sum(cardinality(b)) AS elements, count(*) FILTER (WHERE a IS DISTINCT FROM b) AS mismatches FROM (SELECT k, ARRAY(SELECT g::date FROM jgenerate_series(s.d0::jdate, s.d1::jdate, k) g) AS a, ARRAY(SELECT s.d0 + i * k FROM generate_series(0, (s.d1 - s.d0) / abs(k)) i) AS b FROM (SELECT date '2024-01-01' + o AS d0, date '2024-12-31' AS d1 FROM generate_series(0, 20) o) s, (VALUES (1), (7), (31), (45)) st(k) UNION ALL SELECT -k, ARRAY(SELECT g::date FROM jgenerate_series(s.d1::jdate, s.d0::jdate, -k) g), ARRAY(SELECT s.d1 - i * k FROM generate_series(0, (s.d1 - s.d0) / k) i) FROM (SELECT date '2024-01-01' + o AS d0, date '2024-12-31' AS d1 FROM generate_series(0, 20) o) s, (VALUES (1), (7), (31), (45)) st(k)) q(k, a, b) GROUP BY k ORDER BY k; -- --------------------------------------------------------------------- -- 5. jdate_bin over the same hours. The bins are fixed lengths of elapsed time -- from the origin, so a jtimestamptz bin is not a local day. Each source of 2024 -- (every hour) and of 2020, against core's date_bin on the same instants, and -- against a formula on whole seconds: origin + floor((source - origin) / -- stride) * stride. Origins: UTC midnight, the local midnight of Tehran, -- Paris and Kathmandu, and one after the sources (so the bin start is below -- the source and below the origin). -- --------------------------------------------------------------------- CREATE TEMP TABLE sw_origins (name text, o timestamptz); INSERT INTO sw_origins VALUES ('UTC midnight', timestamptz '2024-01-01 00:00+00'), ('Tehran midnight', timestamptz '2020-03-20 00:00 Asia/Tehran'), ('Paris midnight', timestamptz '2024-01-01 00:00 Europe/Paris'), ('Kathmandu midnight', timestamptz '2024-01-01 00:00 Asia/Kathmandu'), ('after the sources', timestamptz '2030-01-01 00:00+00'); CREATE TEMP TABLE sw_strides (stride interval, secs bigint); INSERT INTO sw_strides SELECT s, extract(epoch FROM s)::bigint FROM (VALUES (interval '15 minutes'), (interval '45 minutes'), (interval '1 hour'), (interval '1 day'), (interval '36 hours'), (interval '7 days')) v(s); CREATE FUNCTION pg_temp.sweep_bin(grid regclass, shift bigint DEFAULT 0) RETURNS TABLE (origin text, cases bigint, vs_core bigint, vs_formula bigint, vs_core_jtimestamp bigint) LANGUAGE plpgsql AS $f$ BEGIN RETURN QUERY EXECUTE format($q$ SELECT o.name, count(*), count(*) FILTER (WHERE jdate_bin(s.stride, g.t::jtimestamptz, o.o::jtimestamptz)::timestamptz IS DISTINCT FROM date_bin(s.stride, g.t, o.o)), count(*) FILTER (WHERE jdate_bin(s.stride, g.t::jtimestamptz, o.o::jtimestamptz)::timestamptz IS DISTINCT FROM to_timestamp(extract(epoch FROM o.o)::bigint + %2$s + floor((extract(epoch FROM g.t)::bigint - extract(epoch FROM o.o)::bigint - %2$s)::numeric / s.secs) * s.secs)), count(*) FILTER (WHERE jdate_bin(s.stride, (g.t AT TIME ZONE 'UTC')::jtimestamp, (o.o AT TIME ZONE 'UTC')::jtimestamp)::timestamp IS DISTINCT FROM date_bin(s.stride, g.t AT TIME ZONE 'UTC', o.o AT TIME ZONE 'UTC')) FROM %1$s g, sw_origins o, sw_strides s GROUP BY o.name ORDER BY o.name COLLATE "C" $q$, grid, shift); END $f$; SELECT '2024' AS grid, * FROM pg_temp.sweep_bin('sw_h2024'); SELECT '2020' AS grid, * FROM pg_temp.sweep_bin('sw_h2020'); -- --------------------------------------------------------------------- -- 6. Negative controls: each sweep above can fail. A deliberately wrong oracle must -- report mismatches (true below), so a zero in a sweep means agreement and not a -- comparison that cannot differ. The first three use the sweep functions -- themselves with a wrong oracle (the hours, the range edges, the bins), the rest -- are the wrong answers a plausible bug would give: Gregorian months, a day of -- 24 hours, a calendar that does not clamp the month end, a series without drift. -- --------------------------------------------------------------------- -- (1) the sweep of every hour with every oracle instant one hour off: every one of the -- 8784 hours must be reported by each of the four counters, in two zones and years SELECT bool_and(plus_day = hours AND minus_day = hours AND plus_month = hours AND minus_month = hours) AS control_hours_skewed_oracle_differs FROM (SELECT * FROM pg_temp.sweep_hours('Europe/Paris', 'sw_h2024', interval '1 hour') UNION ALL SELECT * FROM pg_temp.sweep_hours('Asia/Tehran', 'sw_h2020', interval '1 hour')) x; -- (2) range edges: the oracle with its safe range one hour too wide, or too narrow at -- +15:59, must disagree SELECT bool_or(mismatches > 0) AS control_edge_margin_differs FROM pg_temp.sweep_edges('UTC', interval '1 hour'); SELECT bool_or(mismatches > 0) AS control_edge_margin_differs_at_plus_1559 FROM pg_temp.sweep_edges('<+15:59>-15:59', interval '-1 hour'); -- (3) jdate_bin: a formula with the origin one minute late must disagree SELECT bool_or(vs_formula > 0) AS control_bin_origin_differs FROM pg_temp.sweep_bin('sw_h2024', 60); -- (4) core's Gregorian month in place of the Jalali month: every hour of 2024 in Paris SET TimeZone = 'Europe/Paris'; SELECT count(*) FILTER (WHERE (t::jtimestamptz + interval '1 month')::timestamptz IS DISTINCT FROM t + interval '1 month') > 0 AS control_gregorian_month_differs FROM sw_h2024; -- (5) the day step counted as 24 hours of elapsed time instead of a wall clock day SELECT count(*) FILTER (WHERE (t::jtimestamptz + interval '1 day')::timestamptz IS DISTINCT FROM t + interval '24 hours') > 0 AS control_day_is_not_24_hours FROM sw_h2024; -- (6) the oracle of another zone: the session is Paris, the oracle Kathmandu SELECT count(*) FILTER (WHERE (t::jtimestamptz + interval '1 day')::timestamptz IS DISTINCT FROM ((t AT TIME ZONE 'Asia/Kathmandu') + interval '1 day') AT TIME ZONE 'Asia/Kathmandu') > 0 AS control_wrong_zone_differs FROM sw_h2024; SET TimeZone = 'UTC'; -- (7) month ends: a day that does not exist in the target month rolls into the next -- month (the first of the month plus day - 1 days), as a calendar that does not -- clamp would do; the clamp is what the type does SELECT count(*) FILTER (WHERE (s.jd + make_interval(months => s.n))::jdate IS DISTINCT FROM (pg_temp.ymd(jdate_part('year', s.want)::int, jdate_part('month', s.want)::int, 1)::jdate + (jdate_part('day', s.jd)::int - 1))) > 0 AS control_rolled_month_end_differs FROM sw_steps s WHERE s.unit = 'month' AND s.want IS NOT NULL; -- (8) series: element n + 1 as the start plus n steps (no drift) differs from the series SELECT count(*) FILTER (WHERE ARRAY(SELECT g::timestamp FROM jgenerate_series(st::jtimestamp, '1405-01-01'::jtimestamp, interval '1 month') g) IS DISTINCT FROM ARRAY(SELECT (st::jtimestamp + i * interval '1 month')::timestamp FROM generate_series(0, 40) i WHERE st::jtimestamp + i * interval '1 month' <= '1405-01-01'::jtimestamp)) > 0 AS control_no_drift_differs FROM (VALUES ('1403-01-31 00:00'), ('1403-06-31 00:00')) v(st); -- --------------------------------------------------------------------- -- 7. The volatility catalog of every function Stage J3 added, against the report -- (the feasibility report and the task notes): arithmetic that reads the session -- zone is STABLE, everything else is IMMUTABLE, as the core function it mirrors -- (timestamptz_pl_interval, date_pl_interval, generate_series, date_bin, timezone, -- overlaps); all are PARALLEL SAFE, and STRICT except OVERLAPS (core's is not). -- A function a task added and this list does not know would make the count of -- members of the extension with these names differ from the list. -- --------------------------------------------------------------------- CREATE TEMP TABLE sw_vol (sig text, vol "char", strict boolean, task text); INSERT INTO sw_vol VALUES -- J3.A1: jtimestamp +/- interval, differences ('jtimestamp_pl_interval(jtimestamp,interval)', 'i', true, 'A1'), ('interval_pl_jtimestamp(interval,jtimestamp)', 'i', true, 'A1'), ('jtimestamp_mi_interval(jtimestamp,interval)', 'i', true, 'A1'), ('jtimestamp_mi(jtimestamp,jtimestamp)', 'i', true, 'A1'), ('jdate_mi_jtimestamp(jdate,jtimestamp)', 'i', true, 'A1'), ('jtimestamp_mi_jdate(jtimestamp,jdate)', 'i', true, 'A1'), -- J3.A2: jtimestamptz (session zone: STABLE, the difference of two instants IMMUTABLE), -- jdate + interval and the time operators ('jtimestamptz_pl_interval(jtimestamptz,interval)', 's', true, 'A2'), ('interval_pl_jtimestamptz(interval,jtimestamptz)', 's', true, 'A2'), ('jtimestamptz_mi_interval(jtimestamptz,interval)', 's', true, 'A2'), ('jtimestamptz_mi(jtimestamptz,jtimestamptz)', 'i', true, 'A2'), ('jdate_mi_jtimestamptz(jdate,jtimestamptz)', 's', true, 'A2'), ('jtimestamptz_mi_jdate(jtimestamptz,jdate)', 's', true, 'A2'), ('jdate_pl_interval(jdate,interval)', 'i', true, 'A2'), ('interval_pl_jdate(interval,jdate)', 'i', true, 'A2'), ('jdate_mi_interval(jdate,interval)', 'i', true, 'A2'), ('jdate_pl_time(jdate,time without time zone)', 'i', true, 'A2'), ('time_pl_jdate(time without time zone,jdate)', 'i', true, 'A2'), ('jdate_pl_timetz(jdate,time with time zone)', 'i', true, 'A2'), ('timetz_pl_jdate(time with time zone,jdate)', 'i', true, 'A2'), -- J3.A3: jgenerate_series (the jtimestamptz form that reads the session zone is STABLE, -- the one with a zone argument IMMUTABLE) ('jgenerate_series(jtimestamp,jtimestamp,interval)', 'i', true, 'A3'), ('jgenerate_series(jtimestamptz,jtimestamptz,interval)', 's', true, 'A3'), ('jgenerate_series(jtimestamptz,jtimestamptz,interval,text)', 'i', true, 'A3'), ('jgenerate_series(jdate,jdate,interval)', 'i', true, 'A3'), ('jgenerate_series(jdate,jdate,integer)', 'i', true, 'A3'), -- J3.B1: jdate_bin, AT TIME ZONE, OVERLAPS ('jdate_bin(interval,jtimestamp,jtimestamp)', 'i', true, 'B1'), ('jdate_bin(interval,jtimestamptz,jtimestamptz)', 'i', true, 'B1'), ('pg_catalog.timezone(text,jtimestamp)', 'i', true, 'B1'), ('pg_catalog.timezone(interval,jtimestamp)', 'i', true, 'B1'), ('pg_catalog.timezone(text,jtimestamptz)', 'i', true, 'B1'), ('pg_catalog.timezone(interval,jtimestamptz)', 'i', true, 'B1'), ('pg_catalog.overlaps(jtimestamp,jtimestamp,jtimestamp,jtimestamp)', 'i', false, 'B1'), ('pg_catalog.overlaps(jtimestamptz,jtimestamptz,jtimestamptz,jtimestamptz)', 'i', false, 'B1'); SELECT v.task, v.sig, v.vol AS expected, p.provolatile AS actual, p.provolatile = v.vol AS volatility_ok, p.proisstrict = v.strict AS strict_ok, p.proparallel = 's' AS parallel_safe FROM sw_vol v LEFT JOIN pg_proc p ON p.oid = to_regprocedure(v.sig) ORDER BY v.task, v.sig COLLATE "C"; SELECT count(*) AS listed, count(p.oid) AS found, count(*) FILTER (WHERE p.provolatile = v.vol AND p.proisstrict = v.strict AND p.proparallel = 's') AS all_ok, (SELECT count(*) FROM pg_proc q JOIN pg_depend d ON d.classid = 'pg_proc'::regclass AND d.objid = q.oid AND d.deptype = 'e' AND d.refobjid = (SELECT oid FROM pg_extension WHERE extname = 'jdate') WHERE q.proname IN (SELECT split_part(split_part(sig, '(', 1), '.', 2 - (sig NOT LIKE '%.%')::int) FROM sw_vol)) AS extension_functions_with_these_names FROM sw_vol v LEFT JOIN pg_proc p ON p.oid = to_regprocedure(v.sig);