Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c76c24

Browse files
committed
pg_get_partkeydef: return NULL for non-partitions
Our general rule for pg_get_X(oid) functions is to simply return NULLwhen passed an invalid or inappropriate OID. Teach pg_get_partkeydef todo this also, making it easier for users to use this function whenquerying against tables with both partitions and non-partitions (such aspg_class).As a concrete example, this makes pg_dump's life a little easier.Author: Amit Langote
1 parent49da006 commit0c76c24

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static char *pg_get_indexdef_worker(Oid indexrelid, int colno,
320320
intprettyFlags,boolmissing_ok);
321321
staticchar*pg_get_statisticsext_worker(Oidstatextid,boolmissing_ok);
322322
staticchar*pg_get_partkeydef_worker(Oidrelid,intprettyFlags,
323-
boolattrsOnly);
323+
boolattrsOnly,boolmissing_ok);
324324
staticchar*pg_get_constraintdef_worker(OidconstraintId,boolfullCommand,
325325
intprettyFlags,boolmissing_ok);
326326
statictext*pg_get_expr_worker(text*expr,Oidrelid,constchar*relname,
@@ -1555,10 +1555,14 @@ Datum
15551555
pg_get_partkeydef(PG_FUNCTION_ARGS)
15561556
{
15571557
Oidrelid=PG_GETARG_OID(0);
1558+
char*res;
1559+
1560+
res=pg_get_partkeydef_worker(relid,PRETTYFLAG_INDENT, false, true);
1561+
1562+
if (res==NULL)
1563+
PG_RETURN_NULL();
15581564

1559-
PG_RETURN_TEXT_P(string_to_text(pg_get_partkeydef_worker(relid,
1560-
PRETTYFLAG_INDENT,
1561-
false)));
1565+
PG_RETURN_TEXT_P(string_to_text(res));
15621566
}
15631567

15641568
/* Internal version that just reports the column definitions */
@@ -1568,15 +1572,15 @@ pg_get_partkeydef_columns(Oid relid, bool pretty)
15681572
intprettyFlags;
15691573

15701574
prettyFlags=pretty ?PRETTYFLAG_PAREN |PRETTYFLAG_INDENT :PRETTYFLAG_INDENT;
1571-
returnpg_get_partkeydef_worker(relid,prettyFlags, true);
1575+
returnpg_get_partkeydef_worker(relid,prettyFlags, true, false);
15721576
}
15731577

15741578
/*
15751579
* Internal workhorse to decompile a partition key definition.
15761580
*/
15771581
staticchar*
15781582
pg_get_partkeydef_worker(Oidrelid,intprettyFlags,
1579-
boolattrsOnly)
1583+
boolattrsOnly,boolmissing_ok)
15801584
{
15811585
Form_pg_partitioned_tableform;
15821586
HeapTupletuple;
@@ -1594,7 +1598,11 @@ pg_get_partkeydef_worker(Oid relid, int prettyFlags,
15941598

15951599
tuple=SearchSysCache1(PARTRELID,ObjectIdGetDatum(relid));
15961600
if (!HeapTupleIsValid(tuple))
1601+
{
1602+
if (missing_ok)
1603+
returnNULL;
15971604
elog(ERROR,"cache lookup failed for partition key of %u",relid);
1605+
}
15981606

15991607
form= (Form_pg_partitioned_table)GETSTRUCT(tuple);
16001608

‎src/test/regress/expected/rules.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,6 +3212,12 @@ SELECT pg_get_function_arg_default('pg_class'::regclass, 0);
32123212

32133213
(1 row)
32143214

3215+
SELECT pg_get_partkeydef(0);
3216+
pg_get_partkeydef
3217+
-------------------
3218+
3219+
(1 row)
3220+
32153221
-- test rename for a rule defined on a partitioned table
32163222
CREATE TABLE parted_table (a int) PARTITION BY LIST (a);
32173223
CREATE TABLE parted_table_1 PARTITION OF parted_table FOR VALUES IN (1);

‎src/test/regress/sql/rules.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ SELECT pg_get_function_identity_arguments(0);
11631163
SELECT pg_get_function_result(0);
11641164
SELECT pg_get_function_arg_default(0,0);
11651165
SELECT pg_get_function_arg_default('pg_class'::regclass,0);
1166+
SELECT pg_get_partkeydef(0);
11661167

11671168
-- test rename for a rule defined on a partitioned table
11681169
CREATETABLEparted_table (aint) PARTITION BY LIST (a);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp