How to set not null constraint to columns in postgres

Viewed 1125

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

2 Answers

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;

Try doing it separately for both the columns:

ALTER TABLE myschema.table ALTER COLUMN test_id SET NOT NULL;

ALTER TABLE myschema.table ALTER COLUMN type SET NOT NULL;
Related