sqlpostgresqlddlalter-table

How to set not null constraint to columns in postgres


I tried to set null to columns like following.

ALTER TABLE myschema.table ALTER COLUMN (test_id,type) SET NOT NULL;

But it returned syntax error like Syntax error at or near Line 3, Position 47

Are there any proper way to achieve this ?

If someone has opinion please let me know.

Thanks


Solution

  • You can't provide a list of column in parentheses, you need to use multiple ALTER COLUMN options separated by a comma:

    ALTER TABLE the_table
        ALTER COLUMN test_id set not null, 
        ALTER COLUMN type SET NOT NULL;