Hi all, While testing another patch, I have bumped into the issue of $subject... I should have put some more negative testing from the start on this stuff, here is a culprit query when passing directly an OID: select pg_partition_tree(0);
I think that we should make the function return NULL if the relation defined does not exist, as we usually do for system-facing functions. It is also easier for the caller to know that the relation does not exist instead of having a plpgsql try/catch wrapper or such. Thoughts? -- Michael
diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c index 78dd2b542b..8748869511 100644 --- a/src/backend/utils/adt/partitionfuncs.c +++ b/src/backend/utils/adt/partitionfuncs.c @@ -23,6 +23,7 @@ #include "funcapi.h" #include "utils/fmgrprotos.h" #include "utils/lsyscache.h" +#include "utils/syscache.h" /* @@ -42,6 +43,9 @@ pg_partition_tree(PG_FUNCTION_ARGS) FuncCallContext *funcctx; ListCell **next; + if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(rootrelid))) + PG_RETURN_NULL(); + /* Only allow relation types that can appear in partition trees. */ if (relkind != RELKIND_RELATION && relkind != RELKIND_FOREIGN_TABLE && diff --git a/src/test/regress/expected/partition_info.out b/src/test/regress/expected/partition_info.out index 6b116125e6..2df48fcc1c 100644 --- a/src/test/regress/expected/partition_info.out +++ b/src/test/regress/expected/partition_info.out @@ -6,6 +6,12 @@ SELECT * FROM pg_partition_tree(NULL); -------+-------------+--------+------- (0 rows) +SELECT * FROM pg_partition_tree(0); + relid | parentrelid | isleaf | level +-------+-------------+--------+------- + | | | +(1 row) + -- Test table partition trees CREATE TABLE ptif_test (a int, b int) PARTITION BY range (a); CREATE TABLE ptif_test0 PARTITION OF ptif_test diff --git a/src/test/regress/sql/partition_info.sql b/src/test/regress/sql/partition_info.sql index 5a76f22b05..9b55a7fe5c 100644 --- a/src/test/regress/sql/partition_info.sql +++ b/src/test/regress/sql/partition_info.sql @@ -2,6 +2,7 @@ -- Tests for pg_partition_tree -- SELECT * FROM pg_partition_tree(NULL); +SELECT * FROM pg_partition_tree(0); -- Test table partition trees CREATE TABLE ptif_test (a int, b int) PARTITION BY range (a);
signature.asc
Description: PGP signature