Skip to content

Commit

Permalink
Disallow infinite values for partition interval in create_time_partit…
Browse files Browse the repository at this point in the history
…ions udf (#7822)

PG17 added +/- infinity values for the interval data type
Relevant PG commit:
postgres/postgres@519fc1bd9
  • Loading branch information
naisila authored Dec 30, 2024
1 parent 9e3c329 commit 7dc97d3
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/backend/distributed/sql/citus--12.1-1--13.0-1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

-- bump version to 13.0-1
#include "udfs/citus_prepare_pg_upgrade/13.0-1.sql"
#include "udfs/create_time_partitions/13.0-1.sql"
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
-- citus--13.0-1--12.1-1
-- this is an empty downgrade path since citus--12.1-1--13.0-1.sql is empty

#include "../udfs/create_time_partitions/10.2-1.sql"
58 changes: 58 additions & 0 deletions src/backend/distributed/sql/udfs/create_time_partitions/13.0-1.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ BEGIN
RAISE 'start_from (%) must be older than end_at (%)', start_from, end_at;
END IF;

IF NOT isfinite(partition_interval) THEN
RAISE 'Partition interval must be a finite value';
END IF;

SELECT nspname, relname
INTO schema_name_text, table_name_text
FROM pg_class JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
Expand Down
15 changes: 15 additions & 0 deletions src/test/regress/expected/pg17.out
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,21 @@ ROLLBACK;
NOTICE: issuing ROLLBACK
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
-- End of Testing AT LOCAL option
-- interval can have infinite values
-- Relevant PG17 commit: https://github.com/postgres/postgres/commit/519fc1bd9
-- disallow those in create_time_partitions
-- test create_time_partitions with infinity values
CREATE TABLE date_partitioned_table(
measureid integer,
eventdate date,
measure_data jsonb) PARTITION BY RANGE(eventdate);
SELECT create_time_partitions('date_partitioned_table', INTERVAL 'infinity', '2022-01-01', '2021-01-01');
ERROR: Partition interval must be a finite value
CONTEXT: PL/pgSQL function create_time_partitions(regclass,interval,timestamp with time zone,timestamp with time zone) line XX at RAISE
SELECT create_time_partitions('date_partitioned_table', INTERVAL '-infinity', '2022-01-01', '2021-01-01');
ERROR: Partition interval must be a finite value
CONTEXT: PL/pgSQL function create_time_partitions(regclass,interval,timestamp with time zone,timestamp with time zone) line XX at RAISE
-- end of testing interval with infinite values
\set VERBOSITY terse
SET client_min_messages TO WARNING;
DROP SCHEMA pg17 CASCADE;
Expand Down
15 changes: 15 additions & 0 deletions src/test/regress/sql/pg17.sql
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,21 @@ ROLLBACK;

-- End of Testing AT LOCAL option

-- interval can have infinite values
-- Relevant PG17 commit: https://github.com/postgres/postgres/commit/519fc1bd9
-- disallow those in create_time_partitions

-- test create_time_partitions with infinity values
CREATE TABLE date_partitioned_table(
measureid integer,
eventdate date,
measure_data jsonb) PARTITION BY RANGE(eventdate);

SELECT create_time_partitions('date_partitioned_table', INTERVAL 'infinity', '2022-01-01', '2021-01-01');
SELECT create_time_partitions('date_partitioned_table', INTERVAL '-infinity', '2022-01-01', '2021-01-01');

-- end of testing interval with infinite values

\set VERBOSITY terse
SET client_min_messages TO WARNING;
DROP SCHEMA pg17 CASCADE;
Expand Down

0 comments on commit 7dc97d3

Please sign in to comment.