How to drop multiple columns in postgresql

Postgresql

Postgresql Problem Overview


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"

Postgresql Solutions


Solution 1 - Postgresql

Check this:

ALTER TABLE table DROP COLUMN col1, DROP COLUMN col2;

Solution 2 - Postgresql

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; 

Solution 3 - Postgresql

This worked for me:

alter table your_table_name drop column your_column_name;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionf.ashouriView Question on Stackoverflow
Solution 1 - PostgresqllongView Answer on Stackoverflow
Solution 2 - PostgresqlSomView Answer on Stackoverflow
Solution 3 - PostgresqltimxorView Answer on Stackoverflow