Syntax. The syntax to add a column in a table in PostgreSQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ADD new_column_name column_definition; table_name.
Adding a New column To add a new column to a PostgreSQL table, the ALTER TABLE command is used with the following syntax: ALTER TABLE table-name ADD new-column-name column-definition; The table-name is the name of the table to be modified. The new-column-name is the name of the new column to be added.
Execute the a SQL statement in 'psql' to get the column names of a PostgreSQL table. SELECT column_name FROM INFORMATION_SCHEMA. COLUMNS WHERE TABLE_NAME = 'some_table'; NOTE: Make sure to replace the some_table string that's enclosed in single quotes with an actual table name before you execute the SQL statement.
Try this :
ALTER TABLE table ADD COLUMN col1 int, ADD COLUMN col2 int;
ALTER TABLE IF EXISTS TABLEname
add ADD COLUMN IF NOT EXISTS column_name data_type [column_constraint];
detailed query where column_constraints are optional
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With