192

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

2 Answers 2

334

Try this :

ALTER TABLE table ADD COLUMN col1 int, ADD COLUMN col2 int;
Sign up to request clarification or add additional context in comments.

2 Comments

You might want to reference the docs for posterity, ALTER TABLE [ ONLY ] name [ * ] action [, ... ], postgresql.org/docs/current/static/sql-altertable.html
and to set the default value: ALTER TABLE table ADD COLUMN col1 int default 0, ADD COLUMN col2 text default 'foo';
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

1 Comment

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

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.