On 2025/06/19 14:42, jian he wrote:
> On Wed, Jun 18, 2025 at 10:21 AM Fujii Masao
> <masao.fujii@oss.nttdata.com> wrote:
>>
>> I ran into another issue related to comments on NOT NULL constraints.
>> When using CREATE TABLE ... (LIKE ... INCLUDING ALL), the NOT NULL constraints
>> are copied, but their comments are not. For example:
>>
>> -----------------------------------------------------
>> =# CREATE TABLE t (i int);
>> =# ALTER TABLE t ADD CONSTRAINT my_not_null_i NOT NULL i;
>> =# ALTER TABLE t ADD CONSTRAINT my_check_i CHECK (i > 0);
>> =# COMMENT ON CONSTRAINT my_not_null_i ON t IS 'my not null for i';
>> =# COMMENT ON CONSTRAINT my_check_i ON t IS 'my check for i';
>>
>> =# CREATE TABLE t_copied (LIKE t INCLUDING ALL);
>>
>> As shown, the comment on my_not_null_i is not copied to the new table,
>> even though the constraint itself is. Could this be another oversight
>> in commit 14e87ffa5c5?
>>
>
> hi.
> in transformTableLikeClausem, let cxt(CreateStmtContext) to add
> CommentStmt should just work.
> Please check attached, tests also added.
Thanks for the patch! LGTM.
Just one minor suggestion:
+ /* Copy comments on not-null constraints */
+ if (table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS)
+ {
It might be clearer to move this block after the line:
cxt->nnconstraints = list_concat(cxt->nnconstraints, lst);
That would make the code a bit more readable.
Regards,
--
Fujii Masao
NTT DATA Japan Corporation