Re: Add tab-completion for ALTER TABLE ADD NOT NULL

From: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
To: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Add tab-completion for ALTER TABLE ADD NOT NULL
Date: 2025-06-04 15:34:58
Message-ID: 0070eb25-9f2b-4d55-a30b-183a743ea99b@oss.nttdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2025/06/04 23:38, Álvaro Herrera wrote:
> On 2025-Jun-04, Fujii Masao wrote:
>
>> Hi,
>>
>> psql already supports tab-completion for ALTER TABLE ADD with constraints
>> like CHECK and UNIQUE. However, after commit 14e87ffa5c5 introduced
>> support for adding NOT NULL constraints using ALTER TABLE ADD,
>> tab-completion for that case was missing.
>>
>> The attached patch adds tab-completion support for ALTER TABLE ADD NOT NULL.
>> Thought?
>
> Hmm, did you rewrite the patch I posted at
> https://postgr.es/m/202505111448.bwbfomrymq4b@alvherre.pgsql
> ?

Oh, I missed that patch, thanks for pointing it out!

COMPLETE_WITH("COLUMN", "CONSTRAINT", "CHECK", "UNIQUE", "PRIMARY KEY",
- "EXCLUDE", "FOREIGN KEY");
+ "NOT NULL", "EXCLUDE", "FOREIGN KEY");
}
/* ALTER TABLE xxx ADD [COLUMN] yyy */
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN", MatchAny) ||
- Matches("ALTER", "TABLE", MatchAny, "ADD", MatchAnyExcept("COLUMN|CONSTRAINT|CHECK|UNIQUE|PRIMARY|EXCLUDE|FOREIGN")))
+ Matches("ALTER", "TABLE", MatchAny, "ADD", MatchAnyExcept("COLUMN|CONSTRAINT|CHECK|UNIQUE|PRIMARY|NOT|EXCLUDE|FOREIGN")))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
/* ALTER TABLE xxx ADD CONSTRAINT yyy */
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny))
- COMPLETE_WITH("CHECK", "UNIQUE", "PRIMARY KEY", "EXCLUDE", "FOREIGN KEY");
+ COMPLETE_WITH("CHECK", "UNIQUE", "PRIMARY KEY", "EXCLUDE", "FOREIGN KEY", "NOT NULL");

Just one small style comment: in the documentation, table constraints are
listed in the order CHECK, NOT NULL, UNIQUE, PRIMARY KEY, etc. So it might
be better to follow that same order in the code for consistency in all
three places mentioned above.

Regards,

--
Fujii Masao
NTT DATA Japan Corporation

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joe Conway 2025-06-04 15:44:36 Re: Custom Glibc collation version strings under LOCPATH
Previous Message David E. Wheeler 2025-06-04 15:33:45 Re: [19] Proposal: function markers to indicate collation/ctype sensitivity