mirror of https://github.com/citusdata/citus.git
788 lines
28 KiB
Plaintext
788 lines
28 KiB
Plaintext
-- Show get_missing_partition_ranges function can be only called for timeseries tables
|
|
CREATE TABLE date_partitioned_table(
|
|
measureid integer,
|
|
eventdate date,
|
|
measure_data integer) PARTITION BY RANGE(eventdate);
|
|
SELECT get_missing_partition_ranges('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
|
|
-- Show range values for data partitioned table
|
|
BEGIN;
|
|
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')
|
|
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
|
|
(8 rows)
|
|
|
|
ROLLBACK;
|
|
BEGIN;
|
|
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')
|
|
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
|
|
@ 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');
|
|
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')
|
|
ORDER BY 1,2;
|
|
from_diff | to_diff
|
|
---------------------------------------------------------------------
|
|
@ 45 days ago | @ 50 days ago
|
|
@ 40 days ago | @ 45 days ago
|
|
@ 40 days | @ 35 days
|
|
@ 45 days | @ 40 days
|
|
(4 rows)
|
|
|
|
ROLLBACK;
|
|
-- Show start from date must be before any of existing partition ranges
|
|
BEGIN;
|
|
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')
|
|
ORDER BY 1,2;
|
|
ERROR: given start_from value must be before any of the existing partition ranges
|
|
CONTEXT: PL/pgSQL function get_missing_partition_ranges(regclass,timestamp with time zone,timestamp with time zone) line XX at RAISE
|
|
ROLLBACK;
|
|
-- Show that table must not have manual partitions
|
|
BEGIN;
|
|
SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day');
|
|
create_timeseries_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE date_partitioned_table_manual_partition PARTITION OF date_partitioned_table FOR VALUES FROM '2030-01-01'::date TO '2040-01-01'::date;
|
|
ERROR: syntax error at or near "'2030-01-01'"
|
|
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', '2031-01-01'::date, '2021-01-01'::date)
|
|
ORDER BY 1,2;
|
|
ERROR: current transaction is aborted, commands ignored until end of transaction block
|
|
ROLLBACK;
|
|
DROP TABLE date_partitioned_table;
|
|
-- Show range values for 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
|
|
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
|
|
---------------------------------------------------------------------
|
|
@ 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');
|
|
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')
|
|
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
|
|
@ 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');
|
|
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 '5 days', now() - INTERVAL '5 days')
|
|
ORDER BY 1,2;
|
|
from_diff | to_diff
|
|
---------------------------------------------------------------------
|
|
@ 5 days ago | @ 5 days 6 hours ago
|
|
@ 4 days 18 hours ago | @ 5 days ago
|
|
@ 4 days 12 hours ago | @ 4 days 18 hours ago
|
|
@ 4 days 6 hours ago | @ 4 days 12 hours ago
|
|
@ 4 days ago | @ 4 days 6 hours ago
|
|
@ 3 days 18 hours ago | @ 4 days ago
|
|
@ 3 days 12 hours ago | @ 3 days 18 hours ago
|
|
@ 3 days 6 hours ago | @ 3 days 12 hours ago
|
|
@ 3 days ago | @ 3 days 6 hours ago
|
|
@ 2 days 18 hours ago | @ 3 days ago
|
|
@ 2 days 12 hours ago | @ 2 days 18 hours ago
|
|
@ 2 days 6 hours ago | @ 2 days 12 hours ago
|
|
@ 2 days ago | @ 2 days 6 hours ago
|
|
@ 2 days | @ 1 day 18 hours
|
|
@ 2 days 6 hours | @ 2 days
|
|
@ 2 days 12 hours | @ 2 days 6 hours
|
|
@ 2 days 18 hours | @ 2 days 12 hours
|
|
@ 3 days | @ 2 days 18 hours
|
|
@ 3 days 6 hours | @ 3 days
|
|
@ 3 days 12 hours | @ 3 days 6 hours
|
|
@ 3 days 18 hours | @ 3 days 12 hours
|
|
@ 4 days | @ 3 days 18 hours
|
|
@ 4 days 6 hours | @ 4 days
|
|
@ 4 days 12 hours | @ 4 days 6 hours
|
|
@ 4 days 18 hours | @ 4 days 12 hours
|
|
@ 5 days | @ 4 days 18 hours
|
|
(26 rows)
|
|
|
|
ROLLBACK;
|
|
BEGIN;
|
|
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 '10 days', now() - INTERVAL '10 days')
|
|
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
|
|
@ 8 days | @ 7 days
|
|
@ 9 days | @ 8 days
|
|
@ 10 days | @ 9 days
|
|
(6 rows)
|
|
|
|
ROLLBACK;
|
|
-- Show start from date must be before any of existing partition ranges
|
|
BEGIN;
|
|
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 '10 days', now() - INTERVAL '5 days')
|
|
ORDER BY 1,2;
|
|
ERROR: given start_from value must be before any of the existing partition ranges
|
|
CONTEXT: PL/pgSQL function get_missing_partition_ranges(regclass,timestamp with time zone,timestamp with time zone) line XX at RAISE
|
|
ROLLBACK;
|
|
-- Show that table must not have manual partitions
|
|
BEGIN;
|
|
SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day');
|
|
create_timeseries_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE tstz_partitioned_table_manual_partition PARTITION OF tstz_partitioned_table FOR VALUES FROM '2030-01-01'::timestamptz TO '2040-01-01'::timestamptz;
|
|
ERROR: syntax error at or near "'2030-01-01'"
|
|
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', '2031-01-01'::timestamptz, '2021-01-01'::timestamptz)
|
|
ORDER BY 1,2;
|
|
ERROR: current transaction is aborted, commands ignored until end of transaction block
|
|
ROLLBACK;
|
|
-- Test with different time zones
|
|
SET timezone TO 'UTC';
|
|
BEGIN;
|
|
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')
|
|
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
|
|
@ 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 '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 '10 days', now() - INTERVAL '10 days')
|
|
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
|
|
@ 8 days | @ 7 days
|
|
@ 9 days | @ 8 days
|
|
@ 10 days | @ 9 days
|
|
(6 rows)
|
|
|
|
ROLLBACK;
|
|
SET timezone TO 'Indian/Cocos';
|
|
BEGIN;
|
|
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')
|
|
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
|
|
@ 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 '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 '10 days', now() - INTERVAL '10 days')
|
|
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
|
|
@ 8 days | @ 7 days
|
|
@ 9 days | @ 8 days
|
|
@ 10 days | @ 9 days
|
|
(6 rows)
|
|
|
|
ROLLBACK;
|
|
SET timezone TO 'Japan';
|
|
BEGIN;
|
|
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')
|
|
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
|
|
@ 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 '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 '10 days', now() - INTERVAL '10 days')
|
|
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
|
|
@ 8 days | @ 7 days
|
|
@ 9 days | @ 8 days
|
|
@ 10 days | @ 9 days
|
|
(6 rows)
|
|
|
|
ROLLBACK;
|
|
SET timezone TO 'EST';
|
|
BEGIN;
|
|
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')
|
|
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
|
|
@ 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 '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 '10 days', now() - INTERVAL '10 days')
|
|
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
|
|
@ 8 days | @ 7 days
|
|
@ 9 days | @ 8 days
|
|
@ 10 days | @ 9 days
|
|
(6 rows)
|
|
|
|
ROLLBACK;
|
|
DROP TABLE tstz_partitioned_table;
|
|
SET timezone to DEFAULT;
|
|
-- 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
|
|
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
|
|
---------------------------------------------------------------------
|
|
@ 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');
|
|
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')
|
|
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
|
|
@ 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');
|
|
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 '5 days', now() - INTERVAL '5 days')
|
|
ORDER BY 1,2;
|
|
from_diff | to_diff
|
|
---------------------------------------------------------------------
|
|
@ 5 days ago | @ 5 days 6 hours ago
|
|
@ 4 days 18 hours ago | @ 5 days ago
|
|
@ 4 days 12 hours ago | @ 4 days 18 hours ago
|
|
@ 4 days 6 hours ago | @ 4 days 12 hours ago
|
|
@ 4 days ago | @ 4 days 6 hours ago
|
|
@ 3 days 18 hours ago | @ 4 days ago
|
|
@ 3 days 12 hours ago | @ 3 days 18 hours ago
|
|
@ 3 days 6 hours ago | @ 3 days 12 hours ago
|
|
@ 3 days ago | @ 3 days 6 hours ago
|
|
@ 2 days 18 hours ago | @ 3 days ago
|
|
@ 2 days 12 hours ago | @ 2 days 18 hours ago
|
|
@ 2 days 6 hours ago | @ 2 days 12 hours ago
|
|
@ 2 days ago | @ 2 days 6 hours ago
|
|
@ 2 days | @ 1 day 18 hours
|
|
@ 2 days 6 hours | @ 2 days
|
|
@ 2 days 12 hours | @ 2 days 6 hours
|
|
@ 2 days 18 hours | @ 2 days 12 hours
|
|
@ 3 days | @ 2 days 18 hours
|
|
@ 3 days 6 hours | @ 3 days
|
|
@ 3 days 12 hours | @ 3 days 6 hours
|
|
@ 3 days 18 hours | @ 3 days 12 hours
|
|
@ 4 days | @ 3 days 18 hours
|
|
@ 4 days 6 hours | @ 4 days
|
|
@ 4 days 12 hours | @ 4 days 6 hours
|
|
@ 4 days 18 hours | @ 4 days 12 hours
|
|
@ 5 days | @ 4 days 18 hours
|
|
(26 rows)
|
|
|
|
ROLLBACK;
|
|
BEGIN;
|
|
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 '10 days', now() - INTERVAL '10 days')
|
|
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
|
|
@ 8 days | @ 7 days
|
|
@ 9 days | @ 8 days
|
|
@ 10 days | @ 9 days
|
|
(6 rows)
|
|
|
|
ROLLBACK;
|
|
-- Show start from date must be before any of existing partition ranges
|
|
BEGIN;
|
|
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 '10 days', now() - INTERVAL '5 days')
|
|
ORDER BY 1,2;
|
|
ERROR: given start_from value must be before any of the existing partition ranges
|
|
CONTEXT: PL/pgSQL function get_missing_partition_ranges(regclass,timestamp with time zone,timestamp with time zone) line XX at RAISE
|
|
ROLLBACK;
|
|
DROP TABLE tswtz_partitioned_table;
|