mirror of
https://github.com/postgres/postgres.git
synced 2025-08-18 12:22:09 +03:00
Make CREATE TABLE LIKE copy comments on NOT NULL constraints when requested.
Commit 14e87ffa5c
introduced support for adding comments to NOT NULL
constraints. However, CREATE TABLE LIKE INCLUDING COMMENTS did not copy
these comments to the new table. This was an oversight in that commit.
This commit corrects the behavior by ensuring CREATE TABLE LIKE to also copy
the comments on NOT NULL constraints when INCLUDING COMMENTS is specified.
Author: Jian He <jian.universality@gmail.com>
Co-authored-by: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/127debef-e558-4784-9e24-0d5eaf91e2d1@oss.nttdata.com
This commit is contained in:
@@ -1279,6 +1279,28 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
|
||||
lst = RelationGetNotNullConstraints(RelationGetRelid(relation), false,
|
||||
true);
|
||||
cxt->nnconstraints = list_concat(cxt->nnconstraints, lst);
|
||||
|
||||
/* Copy comments on not-null constraints */
|
||||
if (table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS)
|
||||
{
|
||||
foreach_node(Constraint, nnconstr, lst)
|
||||
{
|
||||
if ((comment = GetComment(get_relation_constraint_oid(RelationGetRelid(relation),
|
||||
nnconstr->conname, false),
|
||||
ConstraintRelationId,
|
||||
0)) != NULL)
|
||||
{
|
||||
CommentStmt *stmt = makeNode(CommentStmt);
|
||||
|
||||
stmt->objtype = OBJECT_TABCONSTRAINT;
|
||||
stmt->object = (Node *) list_make3(makeString(cxt->relation->schemaname),
|
||||
makeString(cxt->relation->relname),
|
||||
makeString(nnconstr->conname));
|
||||
stmt->comment = comment;
|
||||
cxt->alist = lappend(cxt->alist, stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user