Riko Hamblin
Riko Hamblin

Reputation: 61

SQL Error when trying to alter column

I add trying to add a method to be the defualt value of an existing SQL Table Column:

 ALTER TABLE Category ALTER COLUMN category_course 
   CONSTRAINT cat_other_course DEFAULT otherCourse();

However I keep getting this error:

ERROR:  syntax error at or near "CONSTRAINT"
LINE 2: ALTER TABLE Category ALTER COLUMN category_course CONSTRAINT...
                                                      ^
********** Error **********

ERROR: syntax error at or near "CONSTRAINT"
SQL state: 42601

NB: Yes, Category (table) category_course (column) and otherCourse() (function) all exist.

Upvotes: 1

Views: 217

Answers (1)

Rob Blagg
Rob Blagg

Reputation: 280

You need to add SET before DEFAULT. Hope this helps.

ALTER TABLE Category ALTER COLUMN category_course 
CONSTRAINT cat_other_course SET DEFAULT otherCourse();

Upvotes: 1

Related Questions