diff options
author | Robert Haas <rhaas@postgresql.org> | 2017-05-13 12:04:53 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2017-05-13 12:04:53 -0400 |
commit | 1848b73d4576e30c89ba450ad9f169774a6819bf (patch) | |
tree | 47264beb25ffd4d57aab2b25184ed5fa0d243e2f /src/backend/utils/adt/ruleutils.c | |
parent | f8bffe9e6d700fd34759a92e47930ce9ba7dcbd5 (diff) | |
download | postgresql-1848b73d4576e30c89ba450ad9f169774a6819bf.tar.gz postgresql-1848b73d4576e30c89ba450ad9f169774a6819bf.zip |
Teach \d+ to show partitioning constraints.
The fact that we didn't have this in the first place is likely why
the problem fixed by f8bffe9e6d700fd34759a92e47930ce9ba7dcbd5
escaped detection.
Patch by Amit Langote, reviewed and slightly adjusted by me.
Discussion: http://postgr.es/m/CA+TgmoYWnV2GMnYLG-Czsix-E1WGAbo4D+0tx7t9NdfYBDMFsA@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 983b9800ccd..c9bded082ec 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -24,6 +24,7 @@ #include "access/sysattr.h" #include "catalog/dependency.h" #include "catalog/indexing.h" +#include "catalog/partition.h" #include "catalog/pg_aggregate.h" #include "catalog/pg_am.h" #include "catalog/pg_authid.h" @@ -1729,6 +1730,37 @@ pg_get_partkeydef_worker(Oid relid, int prettyFlags, } /* + * pg_get_partition_constraintdef + * + * Returns partition constraint expression as a string for the input relation + */ +Datum +pg_get_partition_constraintdef(PG_FUNCTION_ARGS) +{ + Oid relationId = PG_GETARG_OID(0); + Expr *constr_expr; + int prettyFlags; + List *context; + char *consrc; + + constr_expr = get_partition_qual_relid(relationId); + + /* Quick exit if not a partition */ + if (constr_expr == NULL) + PG_RETURN_NULL(); + + /* + * Deparse and return the constraint expression. + */ + prettyFlags = PRETTYFLAG_INDENT; + context = deparse_context_for(get_relation_name(relationId), relationId); + consrc = deparse_expression_pretty((Node *) constr_expr, context, false, + false, prettyFlags, 0); + + PG_RETURN_TEXT_P(string_to_text(consrc)); +} + +/* * pg_get_constraintdef * * Returns the definition for the constraint, ie, everything that needs to |