Обсуждение: Patch for "CREATE TABLE ... (LIKE ... INCLUDING COMMENTS)"

Поиск
Список
Период
Сортировка

Patch for "CREATE TABLE ... (LIKE ... INCLUDING COMMENTS)"

От
maxzor
Дата:

Hello,

This candidate patch is kind of a bug-solving patch, it applies to one unique file : src/backend/parser/parse_utilcmd.c,
on function transformTableLikeClause.

Its aim is to include the "top-level" comment of the object (table, view, matview...)
that is being copied ; alongside the lower-level comments already in place.

I believe the patch could be ready for application and master branch, but obviously needs review.
It compiled successfully on master/228b0485f471480cf825b7b30ffa3d66bd692c57,
and "worked".
I did not run any regression test as this seems trivial to me.
I suppose it does not need integration in a commitFest either.

-------------------------------------------------------------------------------------------------------
$ diff -c parse_utilcmd_old.c parse_utilcmd.c
*** parse_utilcmd_old.c    2018-12-11 12:44:52.288309000 +0100
--- parse_utilcmd.c    2018-12-11 12:44:52.208308782 +0100
***************
*** 918,923 ****
--- 918,941 ----
                             RelationGetRelationName(relation));
      }
 
+     /*
+      * Copy the comment on the object itself, if requested.
+      */
+     if ((table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS) &&
+         (comment = GetComment(relation->rd_id,
+                               RelationRelationId,
+                               0)) != NULL)
+     {
+         CommentStmt *stmt = makeNode(CommentStmt);
+
+         stmt->objtype = get_relkind_objtype(relation->rd_rel->relkind);
+         stmt->object = (Node *) list_make2(makeString(cxt->relation->schemaname),
+                                            makeString(cxt->relation->relname));
+         stmt->comment = comment;
+
+         cxt->alist = lappend(cxt->alist, stmt);
+     }
+
      tupleDesc = RelationGetDescr(relation);
      constr = tupleDesc->constr;

-------------------------------------------------------------------------------------------------------

Best regards,
Maxime Chambonnet

Re: Patch for "CREATE TABLE ... (LIKE ... INCLUDING COMMENTS)"

От
maxzor
Дата:
...with thunderbird plain-text sorted...


$ diff -c parse_utilcmd_old.c parse_utilcmd.c
*** parse_utilcmd_old.c    2018-12-11 12:44:52.288309000 +0100
--- parse_utilcmd.c    2018-12-11 12:44:52.208308782 +0100
***************
*** 918,923 ****
--- 918,941 ----
                             RelationGetRelationName(relation));
      }

+     /*
+      * Copy the comment on the object itself, if requested.
+      */
+     if ((table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS) &&
+         (comment = GetComment(relation->rd_id,
+                               RelationRelationId,
+                               0)) != NULL)
+     {
+         CommentStmt *stmt = makeNode(CommentStmt);
+
+         stmt->objtype = get_relkind_objtype(relation->rd_rel->relkind);
+         stmt->object = (Node *)
list_make2(makeString(cxt->relation->schemaname),
+                                            makeString(cxt->relation->relname));
+         stmt->comment = comment;
+
+         cxt->alist = lappend(cxt->alist, stmt);
+     }
+
      tupleDesc = RelationGetDescr(relation);
      constr = tupleDesc->constr;



Re: Patch for "CREATE TABLE ... (LIKE ... INCLUDING COMMENTS)"

От
Tom Lane
Дата:
maxzor <maxzor@maxzor.eu> writes:
> This candidate patch is kind of a bug-solving patch, it applies to one
> unique file : src/backend/parser/parse_utilcmd.c,
> on function transformTableLikeClause.
> Its aim is to include the "top-level" comment of the object (table,
> view, matview...)
> that is being copied ; alongside the lower-level comments already in place.

I kind of think the existing behavior is intentional.  LIKE doesn't attempt
to copy other "top level" properties such as ownership.  Partly that's
because there can be only one --- what will you do when there are
multiple LIKE clauses?

            regards, tom lane