aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_utilcmd.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-03-10 14:54:00 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-03-10 14:54:00 -0400
commitcacef172237fd3426b578f81b7414c0de56cbaaf (patch)
treef3740851871185dd888ec48717290e627d416606 /src/backend/parser/parse_utilcmd.c
parentdbf05a14399430751e54cd0b4bd8fb0e4f1fb309 (diff)
downloadpostgresql-cacef172237fd3426b578f81b7414c0de56cbaaf.tar.gz
postgresql-cacef172237fd3426b578f81b7414c0de56cbaaf.zip
Ensure that CREATE TABLE LIKE copies any NO INHERIT constraint property.
Since the documentation about LIKE doesn't say that a copied constraint has properties different from the original, it seems that ignoring a NO INHERIT property doesn't meet the principle of least surprise. So make it copy that. (Note, however, that we still don't copy a NOT VALID property; CREATE TABLE offers no way to do that, plus it seems pointless.) Arguably this is a bug fix; but no back-patch, as it seems barely possible somebody is depending on the current behavior. Ildar Musin and Chris Travers; reviewed by Amit Langote and myself Discussion: https://postgr.es/m/CAONYFtMC6C+3AWCVp7Yd8H87Zn0GxG1_iQG6_bQKbaqYZY0=-g@mail.gmail.com
Diffstat (limited to 'src/backend/parser/parse_utilcmd.c')
-rw-r--r--src/backend/parser/parse_utilcmd.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index af77f1890f9..c1911411d0b 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -1133,12 +1133,14 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
if ((table_like_clause->options & CREATE_TABLE_LIKE_CONSTRAINTS) &&
tupleDesc->constr)
{
+ TupleConstr *constr = tupleDesc->constr;
int ccnum;
- for (ccnum = 0; ccnum < tupleDesc->constr->num_check; ccnum++)
+ for (ccnum = 0; ccnum < constr->num_check; ccnum++)
{
- char *ccname = tupleDesc->constr->check[ccnum].ccname;
- char *ccbin = tupleDesc->constr->check[ccnum].ccbin;
+ char *ccname = constr->check[ccnum].ccname;
+ char *ccbin = constr->check[ccnum].ccbin;
+ bool ccnoinherit = constr->check[ccnum].ccnoinherit;
Constraint *n = makeNode(Constraint);
Node *ccbin_node;
bool found_whole_row;
@@ -1163,8 +1165,9 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
RelationGetRelationName(relation))));
n->contype = CONSTR_CHECK;
- n->location = -1;
n->conname = pstrdup(ccname);
+ n->location = -1;
+ n->is_no_inherit = ccnoinherit;
n->raw_expr = NULL;
n->cooked_expr = nodeToString(ccbin_node);
cxt->ckconstraints = lappend(cxt->ckconstraints, n);