Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop multiple columns in postgresql

Tags:

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"

like image 799
f.ashouri Avatar asked Oct 02 '22 20:10

f.ashouri


People also ask

How do I drop a column in Postgres?

Syntax. The syntax to drop a column in a table in PostgreSQL (using the ALTER TABLE statement) is: ALTER TABLE table_name DROP COLUMN column_name; table_name.

How do I select multiple columns in PostgreSQL?

If you specify a list of columns, you need to place a comma ( , ) between two columns to separate them. If you want to select data from all the columns of the table, you can use an asterisk ( * ) shorthand instead of specifying all the column names.


1 Answers

Check this:

ALTER TABLE table DROP COLUMN col1, DROP COLUMN col2;
like image 290
long Avatar answered Oct 24 '22 23:10

long