170

How do I add multiple columns in one query statement in PostgreSQL using pgadmin3?

isapir
  • 21,295
  • 13
  • 115
  • 116
Hick
  • 35,524
  • 46
  • 151
  • 243

2 Answers2

298

Try this :

ALTER TABLE table ADD COLUMN col1 int, ADD COLUMN col2 int;
Erkan Haspulat
  • 12,032
  • 6
  • 39
  • 45
  • 11
    You might want to reference the docs for posterity, `ALTER TABLE [ ONLY ] name [ * ] action [, ... ]`, http://www.postgresql.org/docs/current/static/sql-altertable.html – mu is too short Mar 10 '11 at 18:23
  • and to set the default value: `ALTER TABLE table ADD COLUMN col1 int default 0, ADD COLUMN col2 text default 'foo';` – Brian D Feb 11 '20 at 15:36
-1
ALTER TABLE  IF EXISTS  TABLEname 
add ADD  COLUMN   IF NOT EXISTS  column_name data_type  [column_constraint];

detailed query where column_constraints are optional

RaM PrabU
  • 415
  • 4
  • 16
  • 3
    Ouch... Neither of the syntaxes above work in Redshift :-( I get errors: ERROR: syntax error at or near "," LINE 1: ALTER TABLE x ADD COLUMN col1 int, ADD COLUMN colX int – Doug P Nov 18 '19 at 23:01