200

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"
Silver Light
  • 44,202
  • 36
  • 123
  • 164

2 Answers2

384

'SET' is forgotten

ALTER TABLE ONLY users ALTER COLUMN lang SET DEFAULT 'en_GB';
Silver Light
  • 44,202
  • 36
  • 123
  • 164
  • 26
    What for `ONLY` is used before the name of the table? – Nik Sumeiko Dec 15 '15 at 09:21
  • 32
    "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" http://www.postgresql.org/docs/9.3/static/sql-altertable.html – Yodan Tauber Dec 20 '15 at 08:41
123

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

ALTER TABLE <table> ALTER COLUMN <column> DROP DEFAULT;
RYS
  • 442
  • 6
  • 22
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753