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

Add tab-completion for ALTER TABLE ADD NOT NULL

From
Fujii Masao
Date:
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?

Regards,

-- 
Fujii Masao
NTT DATA Japan Corporation

Attachment

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

From
Álvaro Herrera
Date:
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
?

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"Nunca se desea ardientemente lo que solo se desea por razón" (F. Alexandre)



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

From
Fujii Masao
Date:

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