226

How do I change column default value in PostgreSQL?

I've tried:

ALTER TABLE ONLY users ALTER COLUMN lang DEFAULT 'en_GB';

But it gave me an error:

ERROR: syntax error at or near "DEFAULT"

2 Answers 2

419

'SET' is forgotten

ALTER TABLE ONLY users ALTER COLUMN lang SET DEFAULT 'en_GB';
Sign up to request clarification or add additional context in comments.

2 Comments

What for ONLY is used before the name of the table?
"If ONLY is specified before the table name, only that table is altered. If ONLY is not specified, the table and all its descendant tables (if any) are altered" postgresql.org/docs/9.3/static/sql-altertable.html
132

If you want to remove the default value constraint, you can do:

ALTER TABLE <table> ALTER COLUMN <column> DROP DEFAULT;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.