Re:doc: Clarify that empty COMMENT string removes the comment

From: zhangqiang <zhang_qiang81(at)163(dot)com>
To: "Chao Li" <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: "PostgreSQL Hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re:doc: Clarify that empty COMMENT string removes the comment
Date: 2026-03-03 03:07:52
Message-ID: 76679fe9.2e67.19cb1aa93f3.Coremail.zhang_qiang81@163.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>At 2026-03-03 09:58:57, "Chao Li" <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>Hi,
>
>While reviewing patch [1] before the holiday vacation, I noticed that the COMMENT ON command treats an empty string as NULL, which effectively removes the comment from the object. Today I also saw discussion [2], which mentioned the same problem.
>
>From the code, it seems the behavior is intentional:
>```
> /* Reduce empty-string to NULL case */
> if (comment != NULL && strlen(comment) == 0)
> comment = NULL;
>```
>
>However, the documentation does not explain this behavior. It currently only says:
>```
>string_literal
> The new comment contents, written as a string literal.
>```
>
>Is it a common pattern that an empty string is treated as NULL, so that the documentation does not need to mention it explicitly? I don’t think so. For example, a similar command, SECURITY LABEL ON, treats an empty string as just an empty string.
>
>This tiny patch enhances the documentation of COMMENT ON to clarify that an empty string is treated as NULL.
>
>[1] https://postgr.es/m/e08cb97f-0364-4002-9cda-3c16b42e4136@uni-muenster.de
>[2] https://postgr.es/m/CAHGQGwFJKg-aT5vajSU1v_B4K129u_SjZ3EGGHFSBhW967gcMA@mail.gmail.com
>
>Best regards,
>--
>Chao Li (Evan)
>HighGo Software Co., Ltd.
>https://www.highgo.com/
>
>
>

Hi hackers,I have verified that using an empty string does indeed delete comments. I agree this patch content enables users to better understand how the database program handles empty strings when using the COMMENT ON command in documentation, thereby improving the user experience.I think it's a good patch.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-03-03 03:16:59 Re: doc: Clarify that empty COMMENT string removes the comment
Previous Message Thomas Munro 2026-03-03 02:55:04 Exploring pass-by-value for small Bitmapset sets