From 7a4293fe373fde8de8e1fc8083726c7f2db40c6f Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Thu, 26 Aug 2021 13:32:21 +0300 Subject: [PATCH] Update ordering on test and add new one for create_missing_partitions --- .../timeseries_create_missing_partitions.out | 646 ++++++++++++++++++ ...imeseries_get_missing_partition_ranges.out | 395 +++++------ ...imeseries_create_drop_timeseries_table.sql | 118 ++-- .../timeseries_create_missing_partitions.sql | 168 +++++ ...imeseries_get_missing_partition_ranges.sql | 145 ++-- src/test/regress/timeseries_schedule | 3 +- 6 files changed, 1159 insertions(+), 316 deletions(-) create mode 100644 src/test/regress/expected/timeseries_create_missing_partitions.out create mode 100644 src/test/regress/sql/timeseries_create_missing_partitions.sql diff --git a/src/test/regress/expected/timeseries_create_missing_partitions.out b/src/test/regress/expected/timeseries_create_missing_partitions.out new file mode 100644 index 000000000..2554feb78 --- /dev/null +++ b/src/test/regress/expected/timeseries_create_missing_partitions.out @@ -0,0 +1,646 @@ +-- Show get_missing_partition_ranges function can be only callede for timeseries tables +CREATE TABLE date_partitioned_table( + measureid integer, + eventdate date, + measure_data integer) PARTITION BY RANGE(eventdate); +SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '15 days'); +ERROR: date_partitioned_table must be timeseries table +CONTEXT: PL/pgSQL function get_missing_partition_ranges(regclass,timestamp with time zone,timestamp with time zone) line XX at RAISE +PL/pgSQL function create_missing_partitions(regclass,timestamp with time zone,timestamp with time zone) line 22 at FOR over SELECT rows +-- Create missing partitions for various ranges on date partitioned table +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '15 days'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 15 days ago | @ 16 days ago + @ 14 days ago | @ 15 days ago + @ 13 days ago | @ 14 days ago + @ 12 days ago | @ 13 days ago + @ 11 days ago | @ 12 days ago + @ 10 days ago | @ 11 days ago + @ 9 days ago | @ 10 days ago + @ 8 days ago | @ 9 days ago + @ 7 days ago | @ 8 days ago + @ 6 days ago | @ 7 days ago + @ 5 days ago | @ 6 days ago + @ 4 days ago | @ 5 days ago + @ 3 days ago | @ 4 days ago + @ 2 days ago | @ 3 days ago + @ 1 day ago | @ 2 days ago + @ 0 | @ 1 day ago + @ 1 day | @ 0 + @ 2 days | @ 1 day + @ 3 days | @ 2 days + @ 4 days | @ 3 days + @ 5 days | @ 4 days + @ 6 days | @ 5 days + @ 7 days | @ 6 days +(23 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '10 days', now() + INTERVAL '10 days'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 10 days ago | @ 11 days ago + @ 9 days ago | @ 10 days ago + @ 8 days ago | @ 9 days ago + @ 7 days ago | @ 8 days ago + @ 6 days ago | @ 7 days ago + @ 5 days ago | @ 6 days ago + @ 4 days ago | @ 5 days ago + @ 3 days ago | @ 4 days ago + @ 2 days ago | @ 3 days ago + @ 1 day ago | @ 2 days ago + @ 0 | @ 1 day ago + @ 1 day | @ 0 + @ 2 days | @ 1 day + @ 3 days | @ 2 days + @ 4 days | @ 3 days + @ 5 days | @ 4 days + @ 6 days | @ 5 days + @ 7 days | @ 6 days +(18 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '45 days', now() + INTERVAL '45 days'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 45 days ago | @ 50 days ago + @ 40 days ago | @ 45 days ago + @ 35 days ago | @ 40 days ago + @ 30 days ago | @ 35 days ago + @ 25 days ago | @ 30 days ago + @ 20 days ago | @ 25 days ago + @ 15 days ago | @ 20 days ago + @ 10 days ago | @ 15 days ago + @ 5 days ago | @ 10 days ago + @ 0 | @ 5 days ago + @ 5 days | @ 0 + @ 10 days | @ 5 days + @ 15 days | @ 10 days + @ 20 days | @ 15 days + @ 25 days | @ 20 days + @ 30 days | @ 25 days + @ 35 days | @ 30 days +(17 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '65 days', now() + INTERVAL '65 days'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 60 days ago | @ 67 days ago + @ 53 days ago | @ 60 days ago + @ 46 days ago | @ 53 days ago + @ 39 days ago | @ 46 days ago + @ 32 days ago | @ 39 days ago + @ 25 days ago | @ 32 days ago + @ 18 days ago | @ 25 days ago + @ 11 days ago | @ 18 days ago + @ 4 days ago | @ 11 days ago + @ 3 days | @ 4 days ago + @ 10 days | @ 3 days + @ 17 days | @ 10 days + @ 24 days | @ 17 days + @ 31 days | @ 24 days + @ 38 days | @ 31 days + @ 45 days | @ 38 days + @ 52 days | @ 45 days +(17 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '5 days', now() + INTERVAL '5 days'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 7 days ago | @ 8 days ago + @ 6 days ago | @ 7 days ago + @ 5 days ago | @ 6 days ago + @ 4 days ago | @ 5 days ago + @ 3 days ago | @ 4 days ago + @ 2 days ago | @ 3 days ago + @ 1 day ago | @ 2 days ago + @ 0 | @ 1 day ago + @ 1 day | @ 0 + @ 2 days | @ 1 day + @ 3 days | @ 2 days + @ 4 days | @ 3 days + @ 5 days | @ 4 days + @ 6 days | @ 5 days + @ 7 days | @ 6 days +(15 rows) + +ROLLBACK; +DROP TABLE date_partitioned_table; +-- Create missing partitions for various ranges on timestamptz partitioned table +CREATE TABLE tstz_partitioned_table( + measureid integer, + eventdatetime timestamp with time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); +BEGIN; + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '1 day'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('hour', now()) - from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp with time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tstz_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 1 day ago | @ 1 day 1 hour ago + @ 23 hours ago | @ 1 day ago + @ 22 hours ago | @ 23 hours ago + @ 21 hours ago | @ 22 hours ago + @ 20 hours ago | @ 21 hours ago + @ 19 hours ago | @ 20 hours ago + @ 18 hours ago | @ 19 hours ago + @ 17 hours ago | @ 18 hours ago + @ 16 hours ago | @ 17 hours ago + @ 15 hours ago | @ 16 hours ago + @ 14 hours ago | @ 15 hours ago + @ 13 hours ago | @ 14 hours ago + @ 12 hours ago | @ 13 hours ago + @ 11 hours ago | @ 12 hours ago + @ 10 hours ago | @ 11 hours ago + @ 9 hours ago | @ 10 hours ago + @ 8 hours ago | @ 9 hours ago + @ 7 hours ago | @ 8 hours ago + @ 6 hours ago | @ 7 hours ago + @ 5 hours ago | @ 6 hours ago + @ 4 hours ago | @ 5 hours ago + @ 3 hours ago | @ 4 hours ago + @ 2 hours ago | @ 3 hours ago + @ 1 hour ago | @ 2 hours ago + @ 0 | @ 1 hour ago + @ 1 hour | @ 0 + @ 2 hours | @ 1 hour + @ 3 hours | @ 2 hours + @ 4 hours | @ 3 hours + @ 5 hours | @ 4 hours + @ 6 hours | @ 5 hours + @ 7 hours | @ 6 hours +(32 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('hour', now()) - from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp with time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tstz_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 1 day ago | @ 1 day 1 hour ago + @ 23 hours ago | @ 1 day ago + @ 22 hours ago | @ 23 hours ago + @ 21 hours ago | @ 22 hours ago + @ 20 hours ago | @ 21 hours ago + @ 19 hours ago | @ 20 hours ago + @ 18 hours ago | @ 19 hours ago + @ 17 hours ago | @ 18 hours ago + @ 16 hours ago | @ 17 hours ago + @ 15 hours ago | @ 16 hours ago + @ 14 hours ago | @ 15 hours ago + @ 13 hours ago | @ 14 hours ago + @ 12 hours ago | @ 13 hours ago + @ 11 hours ago | @ 12 hours ago + @ 10 hours ago | @ 11 hours ago + @ 9 hours ago | @ 10 hours ago + @ 8 hours ago | @ 9 hours ago + @ 7 hours ago | @ 8 hours ago + @ 6 hours ago | @ 7 hours ago + @ 5 hours ago | @ 6 hours ago + @ 4 hours ago | @ 5 hours ago + @ 3 hours ago | @ 4 hours ago + @ 2 hours ago | @ 3 hours ago + @ 1 hour ago | @ 2 hours ago + @ 0 | @ 1 hour ago + @ 1 hour | @ 0 + @ 2 hours | @ 1 hour + @ 3 hours | @ 2 hours + @ 4 hours | @ 3 hours + @ 5 hours | @ 4 hours + @ 6 hours | @ 5 hours + @ 7 hours | @ 6 hours + @ 8 hours | @ 7 hours + @ 9 hours | @ 8 hours + @ 10 hours | @ 9 hours + @ 11 hours | @ 10 hours + @ 12 hours | @ 11 hours + @ 13 hours | @ 12 hours + @ 14 hours | @ 13 hours + @ 15 hours | @ 14 hours + @ 16 hours | @ 15 hours + @ 17 hours | @ 16 hours + @ 18 hours | @ 17 hours + @ 19 hours | @ 18 hours + @ 20 hours | @ 19 hours + @ 21 hours | @ 20 hours + @ 22 hours | @ 21 hours + @ 23 hours | @ 22 hours + @ 1 day | @ 23 hours +(49 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '6 hours'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('hour', now()) - from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp with time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tstz_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 1 day 18 hours ago | @ 2 days ago + @ 1 day 12 hours ago | @ 1 day 18 hours ago + @ 1 day 6 hours ago | @ 1 day 12 hours ago + @ 1 day ago | @ 1 day 6 hours ago + @ 18 hours ago | @ 1 day ago + @ 12 hours ago | @ 18 hours ago + @ 6 hours ago | @ 12 hours ago + @ 0 | @ 6 hours ago + @ 6 hours | @ 0 + @ 12 hours | @ 6 hours + @ 18 hours | @ 12 hours + @ 1 day | @ 18 hours + @ 1 day 6 hours | @ 1 day + @ 1 day 12 hours | @ 1 day 6 hours + @ 1 day 18 hours | @ 1 day 12 hours +(15 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('day', now()) - from_value::timestamp with time zone as from_diff, + date_trunc('day', now()) - to_value::timestamp with time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tstz_partitioned_table'::regclass; + from_diff | to_diff +--------------------------------------------------------------------- + @ 6 days | @ 5 days + @ 1 day ago | @ 2 days ago + @ 3 days | @ 2 days + @ 4 days ago | @ 5 days ago + @ 5 days | @ 4 days + @ 2 days ago | @ 3 days ago + @ 4 days | @ 3 days + @ 3 days ago | @ 4 days ago + @ 7 days | @ 6 days + @ 0 | @ 1 day ago + @ 7 days ago | @ 8 days ago + @ 2 days | @ 1 day + @ 5 days ago | @ 6 days ago + @ 1 day | @ 0 + @ 6 days ago | @ 7 days ago +(15 rows) + +ROLLBACK; +DROP TABLE tstz_partitioned_table; +-- Show range values for timestamp without time zone partitioned table +CREATE TABLE tswtz_partitioned_table( + measureid integer, + eventdatetime timestamp without time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); +BEGIN; + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '1 day'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('hour', now()) - from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp without time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tswtz_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 1 day ago | @ 1 day 1 hour ago + @ 23 hours ago | @ 1 day ago + @ 22 hours ago | @ 23 hours ago + @ 21 hours ago | @ 22 hours ago + @ 20 hours ago | @ 21 hours ago + @ 19 hours ago | @ 20 hours ago + @ 18 hours ago | @ 19 hours ago + @ 17 hours ago | @ 18 hours ago + @ 16 hours ago | @ 17 hours ago + @ 15 hours ago | @ 16 hours ago + @ 14 hours ago | @ 15 hours ago + @ 13 hours ago | @ 14 hours ago + @ 12 hours ago | @ 13 hours ago + @ 11 hours ago | @ 12 hours ago + @ 10 hours ago | @ 11 hours ago + @ 9 hours ago | @ 10 hours ago + @ 8 hours ago | @ 9 hours ago + @ 7 hours ago | @ 8 hours ago + @ 6 hours ago | @ 7 hours ago + @ 5 hours ago | @ 6 hours ago + @ 4 hours ago | @ 5 hours ago + @ 3 hours ago | @ 4 hours ago + @ 2 hours ago | @ 3 hours ago + @ 1 hour ago | @ 2 hours ago + @ 0 | @ 1 hour ago + @ 1 hour | @ 0 + @ 2 hours | @ 1 hour + @ 3 hours | @ 2 hours + @ 4 hours | @ 3 hours + @ 5 hours | @ 4 hours + @ 6 hours | @ 5 hours + @ 7 hours | @ 6 hours +(32 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('hour', now()) - from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp without time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tswtz_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 1 day ago | @ 1 day 1 hour ago + @ 23 hours ago | @ 1 day ago + @ 22 hours ago | @ 23 hours ago + @ 21 hours ago | @ 22 hours ago + @ 20 hours ago | @ 21 hours ago + @ 19 hours ago | @ 20 hours ago + @ 18 hours ago | @ 19 hours ago + @ 17 hours ago | @ 18 hours ago + @ 16 hours ago | @ 17 hours ago + @ 15 hours ago | @ 16 hours ago + @ 14 hours ago | @ 15 hours ago + @ 13 hours ago | @ 14 hours ago + @ 12 hours ago | @ 13 hours ago + @ 11 hours ago | @ 12 hours ago + @ 10 hours ago | @ 11 hours ago + @ 9 hours ago | @ 10 hours ago + @ 8 hours ago | @ 9 hours ago + @ 7 hours ago | @ 8 hours ago + @ 6 hours ago | @ 7 hours ago + @ 5 hours ago | @ 6 hours ago + @ 4 hours ago | @ 5 hours ago + @ 3 hours ago | @ 4 hours ago + @ 2 hours ago | @ 3 hours ago + @ 1 hour ago | @ 2 hours ago + @ 0 | @ 1 hour ago + @ 1 hour | @ 0 + @ 2 hours | @ 1 hour + @ 3 hours | @ 2 hours + @ 4 hours | @ 3 hours + @ 5 hours | @ 4 hours + @ 6 hours | @ 5 hours + @ 7 hours | @ 6 hours + @ 8 hours | @ 7 hours + @ 9 hours | @ 8 hours + @ 10 hours | @ 9 hours + @ 11 hours | @ 10 hours + @ 12 hours | @ 11 hours + @ 13 hours | @ 12 hours + @ 14 hours | @ 13 hours + @ 15 hours | @ 14 hours + @ 16 hours | @ 15 hours + @ 17 hours | @ 16 hours + @ 18 hours | @ 17 hours + @ 19 hours | @ 18 hours + @ 20 hours | @ 19 hours + @ 21 hours | @ 20 hours + @ 22 hours | @ 21 hours + @ 23 hours | @ 22 hours + @ 1 day | @ 23 hours +(49 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('hour', now()) - from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp without time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tswtz_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 1 day 18 hours ago | @ 2 days ago + @ 1 day 12 hours ago | @ 1 day 18 hours ago + @ 1 day 6 hours ago | @ 1 day 12 hours ago + @ 1 day ago | @ 1 day 6 hours ago + @ 18 hours ago | @ 1 day ago + @ 12 hours ago | @ 18 hours ago + @ 6 hours ago | @ 12 hours ago + @ 0 | @ 6 hours ago + @ 6 hours | @ 0 + @ 12 hours | @ 6 hours + @ 18 hours | @ 12 hours + @ 1 day | @ 18 hours + @ 1 day 6 hours | @ 1 day + @ 1 day 12 hours | @ 1 day 6 hours + @ 1 day 18 hours | @ 1 day 12 hours +(15 rows) + +ROLLBACK; +BEGIN; + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + create_missing_partitions +--------------------------------------------------------------------- + t +(1 row) + + SELECT + date_trunc('day', now()) - from_value::timestamp without time zone as from_diff, + date_trunc('day', now()) - to_value::timestamp without time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tswtz_partitioned_table'::regclass + ORDER BY 1,2; + from_diff | to_diff +--------------------------------------------------------------------- + @ 7 days ago | @ 8 days ago + @ 6 days ago | @ 7 days ago + @ 5 days ago | @ 6 days ago + @ 4 days ago | @ 5 days ago + @ 3 days ago | @ 4 days ago + @ 2 days ago | @ 3 days ago + @ 1 day ago | @ 2 days ago + @ 0 | @ 1 day ago + @ 1 day | @ 0 + @ 2 days | @ 1 day + @ 3 days | @ 2 days + @ 4 days | @ 3 days + @ 5 days | @ 4 days + @ 6 days | @ 5 days + @ 7 days | @ 6 days +(15 rows) + +ROLLBACK; +DROP TABLE tswtz_partitioned_table; \ No newline at end of file diff --git a/src/test/regress/expected/timeseries_get_missing_partition_ranges.out b/src/test/regress/expected/timeseries_get_missing_partition_ranges.out index f454cd1e1..5d5ce4bc3 100644 --- a/src/test/regress/expected/timeseries_get_missing_partition_ranges.out +++ b/src/test/regress/expected/timeseries_get_missing_partition_ranges.out @@ -8,112 +8,117 @@ ERROR: date_partitioned_table must be timeseries table CONTEXT: PL/pgSQL function get_missing_partition_ranges(regclass,timestamp with time zone,timestamp with time zone) line XX at RAISE -- Show range values for data partitioned table BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('day', now()) - range_from_value::date as from_diff, - date_trunc('day', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days'); + SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- - @ 8 days ago | @ 9 days ago - @ 9 days ago | @ 10 days ago - @ 10 days ago | @ 11 days ago - @ 11 days ago | @ 12 days ago - @ 12 days ago | @ 13 days ago - @ 13 days ago | @ 14 days ago - @ 14 days ago | @ 15 days ago @ 15 days ago | @ 16 days ago + @ 14 days ago | @ 15 days ago + @ 13 days ago | @ 14 days ago + @ 12 days ago | @ 13 days ago + @ 11 days ago | @ 12 days ago + @ 10 days ago | @ 11 days ago + @ 9 days ago | @ 10 days ago + @ 8 days ago | @ 9 days ago (8 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('day', now()) - range_from_value::date as from_diff, - date_trunc('day', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days', now() - INTERVAL '15 days'); + SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days', now() - INTERVAL '15 days') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- - @ 15 days | @ 14 days - @ 14 days | @ 13 days - @ 13 days | @ 12 days - @ 12 days | @ 11 days - @ 11 days | @ 10 days - @ 10 days | @ 9 days - @ 9 days | @ 8 days - @ 8 days | @ 7 days - @ 8 days ago | @ 9 days ago - @ 9 days ago | @ 10 days ago - @ 10 days ago | @ 11 days ago - @ 11 days ago | @ 12 days ago - @ 12 days ago | @ 13 days ago - @ 13 days ago | @ 14 days ago - @ 14 days ago | @ 15 days ago @ 15 days ago | @ 16 days ago + @ 14 days ago | @ 15 days ago + @ 13 days ago | @ 14 days ago + @ 12 days ago | @ 13 days ago + @ 11 days ago | @ 12 days ago + @ 10 days ago | @ 11 days ago + @ 9 days ago | @ 10 days ago + @ 8 days ago | @ 9 days ago + @ 8 days | @ 7 days + @ 9 days | @ 8 days + @ 10 days | @ 9 days + @ 11 days | @ 10 days + @ 12 days | @ 11 days + @ 13 days | @ 12 days + @ 14 days | @ 13 days + @ 15 days | @ 14 days (16 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('day', now()) - range_from_value::date as from_diff, - date_trunc('day', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '45 days', now() - INTERVAL '45 days'); + SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '45 days', now() - INTERVAL '45 days') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- - @ 45 days | @ 40 days - @ 40 days | @ 35 days - @ 40 days ago | @ 45 days ago @ 45 days ago | @ 50 days ago + @ 40 days ago | @ 45 days ago + @ 40 days | @ 35 days + @ 45 days | @ 40 days (4 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('week', now()) - range_from_value::date as from_diff, - date_trunc('week', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '65 days', now() - INTERVAL '65 days'); + SELECT + date_trunc('week', now()) - range_from_value::date as from_diff, + date_trunc('week', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '65 days', now() - INTERVAL '65 days') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- - @ 63 days | @ 56 days - @ 56 days | @ 49 days - @ 56 days ago | @ 63 days ago @ 63 days ago | @ 70 days ago + @ 56 days ago | @ 63 days ago + @ 56 days | @ 49 days + @ 63 days | @ 56 days (4 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('day', now()) - range_from_value::date as from_diff, - date_trunc('day', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- (0 rows) @@ -126,115 +131,119 @@ CREATE TABLE tstz_partitioned_table( eventdatetime timestamp with time zone, measure_data integer) PARTITION BY RANGE(eventdatetime); BEGIN; -SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff -FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff + FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- - @ 8 hours ago | @ 9 hours ago - @ 9 hours ago | @ 10 hours ago - @ 10 hours ago | @ 11 hours ago - @ 11 hours ago | @ 12 hours ago - @ 12 hours ago | @ 13 hours ago - @ 13 hours ago | @ 14 hours ago - @ 14 hours ago | @ 15 hours ago - @ 15 hours ago | @ 16 hours ago - @ 16 hours ago | @ 17 hours ago - @ 17 hours ago | @ 18 hours ago - @ 18 hours ago | @ 19 hours ago - @ 19 hours ago | @ 20 hours ago - @ 20 hours ago | @ 21 hours ago - @ 21 hours ago | @ 22 hours ago - @ 22 hours ago | @ 23 hours ago - @ 23 hours ago | @ 1 day ago @ 1 day ago | @ 1 day 1 hour ago + @ 23 hours ago | @ 1 day ago + @ 22 hours ago | @ 23 hours ago + @ 21 hours ago | @ 22 hours ago + @ 20 hours ago | @ 21 hours ago + @ 19 hours ago | @ 20 hours ago + @ 18 hours ago | @ 19 hours ago + @ 17 hours ago | @ 18 hours ago + @ 16 hours ago | @ 17 hours ago + @ 15 hours ago | @ 16 hours ago + @ 14 hours ago | @ 15 hours ago + @ 13 hours ago | @ 14 hours ago + @ 12 hours ago | @ 13 hours ago + @ 11 hours ago | @ 12 hours ago + @ 10 hours ago | @ 11 hours ago + @ 9 hours ago | @ 10 hours ago + @ 8 hours ago | @ 9 hours ago (17 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff -FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff + FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- - @ 1 day | @ 23 hours - @ 23 hours | @ 22 hours - @ 22 hours | @ 21 hours - @ 21 hours | @ 20 hours - @ 20 hours | @ 19 hours - @ 19 hours | @ 18 hours - @ 18 hours | @ 17 hours - @ 17 hours | @ 16 hours - @ 16 hours | @ 15 hours - @ 15 hours | @ 14 hours - @ 14 hours | @ 13 hours - @ 13 hours | @ 12 hours - @ 12 hours | @ 11 hours - @ 11 hours | @ 10 hours - @ 10 hours | @ 9 hours - @ 9 hours | @ 8 hours - @ 8 hours | @ 7 hours - @ 8 hours ago | @ 9 hours ago - @ 9 hours ago | @ 10 hours ago - @ 10 hours ago | @ 11 hours ago - @ 11 hours ago | @ 12 hours ago - @ 12 hours ago | @ 13 hours ago - @ 13 hours ago | @ 14 hours ago - @ 14 hours ago | @ 15 hours ago - @ 15 hours ago | @ 16 hours ago - @ 16 hours ago | @ 17 hours ago - @ 17 hours ago | @ 18 hours ago - @ 18 hours ago | @ 19 hours ago - @ 19 hours ago | @ 20 hours ago - @ 20 hours ago | @ 21 hours ago - @ 21 hours ago | @ 22 hours ago - @ 22 hours ago | @ 23 hours ago - @ 23 hours ago | @ 1 day ago @ 1 day ago | @ 1 day 1 hour ago + @ 23 hours ago | @ 1 day ago + @ 22 hours ago | @ 23 hours ago + @ 21 hours ago | @ 22 hours ago + @ 20 hours ago | @ 21 hours ago + @ 19 hours ago | @ 20 hours ago + @ 18 hours ago | @ 19 hours ago + @ 17 hours ago | @ 18 hours ago + @ 16 hours ago | @ 17 hours ago + @ 15 hours ago | @ 16 hours ago + @ 14 hours ago | @ 15 hours ago + @ 13 hours ago | @ 14 hours ago + @ 12 hours ago | @ 13 hours ago + @ 11 hours ago | @ 12 hours ago + @ 10 hours ago | @ 11 hours ago + @ 9 hours ago | @ 10 hours ago + @ 8 hours ago | @ 9 hours ago + @ 8 hours | @ 7 hours + @ 9 hours | @ 8 hours + @ 10 hours | @ 9 hours + @ 11 hours | @ 10 hours + @ 12 hours | @ 11 hours + @ 13 hours | @ 12 hours + @ 14 hours | @ 13 hours + @ 15 hours | @ 14 hours + @ 16 hours | @ 15 hours + @ 17 hours | @ 16 hours + @ 18 hours | @ 17 hours + @ 19 hours | @ 18 hours + @ 20 hours | @ 19 hours + @ 21 hours | @ 20 hours + @ 22 hours | @ 21 hours + @ 23 hours | @ 22 hours + @ 1 day | @ 23 hours (34 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '6 hours'); + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '6 hours'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff -FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff + FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- (0 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('day', now()) - range_from_value::timestamp with time zone as from_diff, - date_trunc('day', now()) - range_to_value::timestamp with time zone as to_diff -FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + SELECT + date_trunc('day', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('day', now()) - range_to_value::timestamp with time zone as to_diff + FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- (0 rows) @@ -247,115 +256,119 @@ CREATE TABLE tswtz_partitioned_table( eventdatetime timestamp without time zone, measure_data integer) PARTITION BY RANGE(eventdatetime); BEGIN; -SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff -FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff + FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- - @ 8 hours ago | @ 9 hours ago - @ 9 hours ago | @ 10 hours ago - @ 10 hours ago | @ 11 hours ago - @ 11 hours ago | @ 12 hours ago - @ 12 hours ago | @ 13 hours ago - @ 13 hours ago | @ 14 hours ago - @ 14 hours ago | @ 15 hours ago - @ 15 hours ago | @ 16 hours ago - @ 16 hours ago | @ 17 hours ago - @ 17 hours ago | @ 18 hours ago - @ 18 hours ago | @ 19 hours ago - @ 19 hours ago | @ 20 hours ago - @ 20 hours ago | @ 21 hours ago - @ 21 hours ago | @ 22 hours ago - @ 22 hours ago | @ 23 hours ago - @ 23 hours ago | @ 1 day ago @ 1 day ago | @ 1 day 1 hour ago + @ 23 hours ago | @ 1 day ago + @ 22 hours ago | @ 23 hours ago + @ 21 hours ago | @ 22 hours ago + @ 20 hours ago | @ 21 hours ago + @ 19 hours ago | @ 20 hours ago + @ 18 hours ago | @ 19 hours ago + @ 17 hours ago | @ 18 hours ago + @ 16 hours ago | @ 17 hours ago + @ 15 hours ago | @ 16 hours ago + @ 14 hours ago | @ 15 hours ago + @ 13 hours ago | @ 14 hours ago + @ 12 hours ago | @ 13 hours ago + @ 11 hours ago | @ 12 hours ago + @ 10 hours ago | @ 11 hours ago + @ 9 hours ago | @ 10 hours ago + @ 8 hours ago | @ 9 hours ago (17 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff -FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff + FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- - @ 1 day | @ 23 hours - @ 23 hours | @ 22 hours - @ 22 hours | @ 21 hours - @ 21 hours | @ 20 hours - @ 20 hours | @ 19 hours - @ 19 hours | @ 18 hours - @ 18 hours | @ 17 hours - @ 17 hours | @ 16 hours - @ 16 hours | @ 15 hours - @ 15 hours | @ 14 hours - @ 14 hours | @ 13 hours - @ 13 hours | @ 12 hours - @ 12 hours | @ 11 hours - @ 11 hours | @ 10 hours - @ 10 hours | @ 9 hours - @ 9 hours | @ 8 hours - @ 8 hours | @ 7 hours - @ 8 hours ago | @ 9 hours ago - @ 9 hours ago | @ 10 hours ago - @ 10 hours ago | @ 11 hours ago - @ 11 hours ago | @ 12 hours ago - @ 12 hours ago | @ 13 hours ago - @ 13 hours ago | @ 14 hours ago - @ 14 hours ago | @ 15 hours ago - @ 15 hours ago | @ 16 hours ago - @ 16 hours ago | @ 17 hours ago - @ 17 hours ago | @ 18 hours ago - @ 18 hours ago | @ 19 hours ago - @ 19 hours ago | @ 20 hours ago - @ 20 hours ago | @ 21 hours ago - @ 21 hours ago | @ 22 hours ago - @ 22 hours ago | @ 23 hours ago - @ 23 hours ago | @ 1 day ago @ 1 day ago | @ 1 day 1 hour ago + @ 23 hours ago | @ 1 day ago + @ 22 hours ago | @ 23 hours ago + @ 21 hours ago | @ 22 hours ago + @ 20 hours ago | @ 21 hours ago + @ 19 hours ago | @ 20 hours ago + @ 18 hours ago | @ 19 hours ago + @ 17 hours ago | @ 18 hours ago + @ 16 hours ago | @ 17 hours ago + @ 15 hours ago | @ 16 hours ago + @ 14 hours ago | @ 15 hours ago + @ 13 hours ago | @ 14 hours ago + @ 12 hours ago | @ 13 hours ago + @ 11 hours ago | @ 12 hours ago + @ 10 hours ago | @ 11 hours ago + @ 9 hours ago | @ 10 hours ago + @ 8 hours ago | @ 9 hours ago + @ 8 hours | @ 7 hours + @ 9 hours | @ 8 hours + @ 10 hours | @ 9 hours + @ 11 hours | @ 10 hours + @ 12 hours | @ 11 hours + @ 13 hours | @ 12 hours + @ 14 hours | @ 13 hours + @ 15 hours | @ 14 hours + @ 16 hours | @ 15 hours + @ 17 hours | @ 16 hours + @ 18 hours | @ 17 hours + @ 19 hours | @ 18 hours + @ 20 hours | @ 19 hours + @ 21 hours | @ 20 hours + @ 22 hours | @ 21 hours + @ 23 hours | @ 22 hours + @ 1 day | @ 23 hours (34 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff -FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff + FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- (0 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT - date_trunc('day', now()) - range_from_value::timestamp without time zone as from_diff, - date_trunc('day', now()) - range_to_value::timestamp without time zone as to_diff -FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + SELECT + date_trunc('day', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('day', now()) - range_to_value::timestamp without time zone as to_diff + FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days') + ORDER BY 1,2; from_diff | to_diff --------------------------------------------------------------------- (0 rows) diff --git a/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql b/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql index 6a391e9fd..95f9bd8e2 100644 --- a/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql +++ b/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql @@ -57,23 +57,23 @@ SELECT create_timeseries_table('date_partitioned_table', INTERVAL '3 hours'); SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day 15 minutes'); BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '2 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '2 days'); ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month'); ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month 15 weeks 3 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month 15 weeks 3 days'); ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 year 1 month 15 weeks 3 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 year 1 month 15 weeks 3 days'); ROLLBACK; DROP TABLE date_partitioned_table; @@ -92,11 +92,11 @@ SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 wee SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', retention_threshold => INTERVAL '5 days'); BEGIN; -SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', compression_threshold => INTERVAL '10 days'); + SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', compression_threshold => INTERVAL '10 days'); ROLLBACK; BEGIN; -SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', compression_threshold => INTERVAL '10 days', retention_threshold => INTERVAL '15 days'); + SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', compression_threshold => INTERVAL '10 days', retention_threshold => INTERVAL '15 days'); ROLLBACK; DROP TABLE ts_comp_date_partitioned_table; @@ -112,11 +112,11 @@ SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '2 hou SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '2 hours', retention_threshold => INTERVAL '1 hour'); BEGIN; -SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '2 hours', compression_threshold => INTERVAL '6 hours'); + SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '2 hours', compression_threshold => INTERVAL '6 hours'); ROLLBACK; BEGIN; -SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '90 minutes', compression_threshold => INTERVAL '180 minutes', retention_threshold => INTERVAL '360 minutes'); + SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '90 minutes', compression_threshold => INTERVAL '180 minutes', retention_threshold => INTERVAL '360 minutes'); ROLLBACK; DROP TABLE ts_comp_tstz_partitioned_table; @@ -130,11 +130,11 @@ CREATE TABLE param_test_partitioned_table( SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', premake_interval_count => 7, start_from => now()); BEGIN; -SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', premake_interval_count => 7); + SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', premake_interval_count => 7); ROLLBACK; BEGIN; -SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', start_from => now()); + SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', start_from => now()); ROLLBACK; DROP TABLE param_test_partitioned_table; @@ -146,31 +146,31 @@ CREATE TABLE count_test_partitioned_table( measure_data integer) PARTITION BY RANGE(eventdatetime); BEGIN; -SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '1 minute', postmake_interval_count => 0, premake_interval_count => 0); -SELECT count(*) -FROM pg_catalog.time_partitions -WHERE parent_table = 'count_test_partitioned_table'::regclass; + SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '1 minute', postmake_interval_count => 0, premake_interval_count => 0); + SELECT count(*) + FROM pg_catalog.time_partitions + WHERE parent_table = 'count_test_partitioned_table'::regclass; ROLLBACK; BEGIN; -SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '1 hour', postmake_interval_count => 0, premake_interval_count => 5); -SELECT count(*) -FROM pg_catalog.time_partitions -WHERE parent_table = 'count_test_partitioned_table'::regclass; + SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '1 hour', postmake_interval_count => 0, premake_interval_count => 5); + SELECT count(*) + FROM pg_catalog.time_partitions + WHERE parent_table = 'count_test_partitioned_table'::regclass; ROLLBACK; BEGIN; -SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '2 weeks', postmake_interval_count => 5, premake_interval_count => 0); -SELECT count(*) -FROM pg_catalog.time_partitions -WHERE parent_table = 'count_test_partitioned_table'::regclass; + SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '2 weeks', postmake_interval_count => 5, premake_interval_count => 0); + SELECT count(*) + FROM pg_catalog.time_partitions + WHERE parent_table = 'count_test_partitioned_table'::regclass; ROLLBACK; BEGIN; -SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '2 months', postmake_interval_count => 3, premake_interval_count => 4); -SELECT count(*) -FROM pg_catalog.time_partitions -WHERE parent_table = 'count_test_partitioned_table'::regclass; + SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '2 months', postmake_interval_count => 3, premake_interval_count => 4); + SELECT count(*) + FROM pg_catalog.time_partitions + WHERE parent_table = 'count_test_partitioned_table'::regclass; ROLLBACK; DROP TABLE count_test_partitioned_table; @@ -182,39 +182,39 @@ CREATE TABLE range_check_test_partitioned_table( measure_data integer) PARTITION BY RANGE(eventdatetime); BEGIN; -SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 hour'); -SELECT partition, - date_trunc('hour',now()) - from_value::timestamptz as from_diff, - date_trunc('hour', now()) - to_value::timestamptz as to_diff -FROM pg_catalog.time_partitions -ORDER BY 1; + SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 hour'); + SELECT partition, + date_trunc('hour',now()) - from_value::timestamptz as from_diff, + date_trunc('hour', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions + ORDER BY 1; ROLLBACK; BEGIN; -SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 day', postmake_interval_count => 5); -SELECT partition, - date_trunc('day',now()) - from_value::timestamptz as from_diff, - date_trunc('day', now()) - to_value::timestamptz as to_diff -FROM pg_catalog.time_partitions -ORDER BY 1; + SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 day', postmake_interval_count => 5); + SELECT partition, + date_trunc('day',now()) - from_value::timestamptz as from_diff, + date_trunc('day', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions + ORDER BY 1; ROLLBACK; BEGIN; -SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', premake_interval_count => 3); -SELECT partition, - date_trunc('week',now()) - from_value::timestamptz as from_diff, - date_trunc('week', now()) - to_value::timestamptz as to_diff -FROM pg_catalog.time_partitions -ORDER BY 1; + SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', premake_interval_count => 3); + SELECT partition, + date_trunc('week',now()) - from_value::timestamptz as from_diff, + date_trunc('week', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions + ORDER BY 1; ROLLBACK; BEGIN; -SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', start_from => now() - INTERVAL '4 weeks'); -SELECT partition, - date_trunc('week',now()) - from_value::timestamptz as from_diff, - date_trunc('week', now()) - to_value::timestamptz as to_diff -FROM pg_catalog.time_partitions -ORDER BY 1; + SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', start_from => now() - INTERVAL '4 weeks'); + SELECT partition, + date_trunc('week',now()) - from_value::timestamptz as from_diff, + date_trunc('week', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions + ORDER BY 1; ROLLBACK; -- Check drop table @@ -229,12 +229,12 @@ DROP TABLE drop_check_test_partitioned_table; SELECT * FROM citus_timeseries.citus_timeseries_tables; BEGIN; -CREATE TABLE drop_check_test_partitioned_table( - measureid integer, - eventdatetime timestamp with time zone, - measure_data integer) PARTITION BY RANGE(eventdatetime); -SELECT create_timeseries_table('drop_check_test_partitioned_table', INTERVAL '2 hours'); -SELECT * FROM citus_timeseries.citus_timeseries_tables; -DROP TABLE drop_check_test_partitioned_table; -SELECT * FROM citus_timeseries.citus_timeseries_tables; + CREATE TABLE drop_check_test_partitioned_table( + measureid integer, + eventdatetime timestamp with time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); + SELECT create_timeseries_table('drop_check_test_partitioned_table', INTERVAL '2 hours'); + SELECT * FROM citus_timeseries.citus_timeseries_tables; + DROP TABLE drop_check_test_partitioned_table; + SELECT * FROM citus_timeseries.citus_timeseries_tables; COMMIT; diff --git a/src/test/regress/sql/timeseries_create_missing_partitions.sql b/src/test/regress/sql/timeseries_create_missing_partitions.sql new file mode 100644 index 000000000..0801685f3 --- /dev/null +++ b/src/test/regress/sql/timeseries_create_missing_partitions.sql @@ -0,0 +1,168 @@ +-- Show get_missing_partition_ranges function can be only callede for timeseries tables +CREATE TABLE date_partitioned_table( + measureid integer, + eventdate date, + measure_data integer) PARTITION BY RANGE(eventdate); + +SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '15 days'); + +-- Create missing partitions for various ranges on date partitioned table +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '15 days'); + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '10 days', now() + INTERVAL '10 days'); + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '45 days', now() + INTERVAL '45 days'); + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '65 days', now() + INTERVAL '65 days'); + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '5 days', now() + INTERVAL '5 days'); + SELECT + date_trunc('day', now()) - from_value::date as from_diff, + date_trunc('day', now()) - to_value::date as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'date_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +DROP TABLE date_partitioned_table; + +-- Create missing partitions for various ranges on timestamptz partitioned table +CREATE TABLE tstz_partitioned_table( + measureid integer, + eventdatetime timestamp with time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); + +BEGIN; + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp with time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tstz_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp with time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tstz_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '6 hours'); + SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp with time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tstz_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); + SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + SELECT + date_trunc('day', now()) - from_value::timestamp with time zone as from_diff, + date_trunc('day', now()) - to_value::timestamp with time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tstz_partitioned_table'::regclass; +ROLLBACK; + +DROP TABLE tstz_partitioned_table; + +-- Show range values for timestamp without time zone partitioned table +CREATE TABLE tswtz_partitioned_table( + measureid integer, + eventdatetime timestamp without time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); + +BEGIN; + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp without time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tswtz_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp without time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tswtz_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); + SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT + date_trunc('hour', now()) - from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - to_value::timestamp without time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tswtz_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +BEGIN; + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); + SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + SELECT + date_trunc('day', now()) - from_value::timestamp without time zone as from_diff, + date_trunc('day', now()) - to_value::timestamp without time zone as to_diff + FROM pg_catalog.time_partitions + WHERE parent_table = 'tswtz_partitioned_table'::regclass + ORDER BY 1,2; +ROLLBACK; + +DROP TABLE tswtz_partitioned_table; diff --git a/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql b/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql index 288e5d16d..b2313d41a 100644 --- a/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql +++ b/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql @@ -8,43 +8,48 @@ SELECT get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL ' -- Show range values for data partitioned table BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); -SELECT - date_trunc('day', now()) - range_from_value::date as from_diff, - date_trunc('day', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); -SELECT - date_trunc('day', now()) - range_from_value::date as from_diff, - date_trunc('day', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days', now() - INTERVAL '15 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days', now() - INTERVAL '15 days') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); -SELECT - date_trunc('day', now()) - range_from_value::date as from_diff, - date_trunc('day', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '45 days', now() - INTERVAL '45 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); + SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '45 days', now() - INTERVAL '45 days') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); -SELECT - date_trunc('week', now()) - range_from_value::date as from_diff, - date_trunc('week', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '65 days', now() - INTERVAL '65 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); + SELECT + date_trunc('week', now()) - range_from_value::date as from_diff, + date_trunc('week', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '65 days', now() - INTERVAL '65 days') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); -SELECT - date_trunc('day', now()) - range_from_value::date as from_diff, - date_trunc('day', now()) - range_to_value::date as to_diff -FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff + FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days') + ORDER BY 1,2; ROLLBACK; DROP TABLE date_partitioned_table; @@ -54,36 +59,41 @@ CREATE TABLE tstz_partitioned_table( measureid integer, eventdatetime timestamp with time zone, measure_data integer) PARTITION BY RANGE(eventdatetime); + BEGIN; -SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); -SELECT - date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff -FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day'); + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff + FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); -SELECT - date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff -FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff + FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '6 hours'); -SELECT - date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff -FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '6 hours'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff + FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); -SELECT - date_trunc('day', now()) - range_from_value::timestamp with time zone as from_diff, - date_trunc('day', now()) - range_to_value::timestamp with time zone as to_diff -FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); + SELECT + date_trunc('day', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('day', now()) - range_to_value::timestamp with time zone as to_diff + FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days') + ORDER BY 1,2; ROLLBACK; DROP TABLE tstz_partitioned_table; @@ -93,36 +103,41 @@ CREATE TABLE tswtz_partitioned_table( measureid integer, eventdatetime timestamp without time zone, measure_data integer) PARTITION BY RANGE(eventdatetime); + BEGIN; -SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); -SELECT - date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff -FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day'); + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff + FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); -SELECT - date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff -FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff + FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); -SELECT - date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, - date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff -FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); + SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff + FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') + ORDER BY 1,2; ROLLBACK; BEGIN; -SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); -SELECT - date_trunc('day', now()) - range_from_value::timestamp without time zone as from_diff, - date_trunc('day', now()) - range_to_value::timestamp without time zone as to_diff -FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); + SELECT + date_trunc('day', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('day', now()) - range_to_value::timestamp without time zone as to_diff + FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days') + ORDER BY 1,2; ROLLBACK; DROP TABLE tswtz_partitioned_table; diff --git a/src/test/regress/timeseries_schedule b/src/test/regress/timeseries_schedule index 976997ac7..cd30f6f6e 100644 --- a/src/test/regress/timeseries_schedule +++ b/src/test/regress/timeseries_schedule @@ -3,4 +3,5 @@ test: multi_test_helpers multi_test_helpers_superuser test: multi_test_catalog_views test: timeseries_create_drop_timeseries_table -test: timeseries_get_missing_partition_ranges \ No newline at end of file +test: timeseries_get_missing_partition_ranges +test: timeseries_create_missing_partitions \ No newline at end of file