f.ashouri
f.ashouri

Reputation: 5667

How to drop multiple columns in PostgreSQL

I want to drop 200 columns in my table in PostgreSQL. I tried:

ALTER TABLE my_table
DROP COLUMN col1, col2

But I get an error like this:

ERROR: syntax error at or near "col2"

Upvotes: 167

Views: 93649

Answers (3)

long
long

Reputation: 4318

As per the docs, you can do this:

ALTER TABLE table DROP COLUMN col1, DROP COLUMN col2;

(You may need to wrap some of your column names in " quotes if they happen to be keywords.)

Upvotes: 317

Som
Som

Reputation: 1627

Thanks long & Ondrej - below commands worked for me,

ALTER TABLE table_name DROP COLUMN column_name_1,DROP COLUMN column_name_2,DROP COLUMN column_name_3; 

ALTER TABLE table_name DROP column_name_1,DROP column_name_2,DROP column_name_3; 

Upvotes: -1

Tim Siwula
Tim Siwula

Reputation: 983

This worked for me:

alter table your_table_name drop column your_column_name;

Upvotes: -5

Related Questions