postgresqlHow do I add a column to a PostgreSQL table?
Adding a column to a PostgreSQL table is a common database operation. To do this, you will need to use the ALTER TABLE command. Here is an example of how to add a new column to a table:
ALTER TABLE table_name
ADD COLUMN column_name data_type;
This command will add a new column named column_name to the table_name table with the data type data_type. For example, if you wanted to add a column named age to the users table with the data type integer, you would use the following command:
ALTER TABLE users
ADD COLUMN age integer;
This command will not return any output.
Code explanation
ALTER TABLE: The command used to alter a table in PostgreSQLtable_name: The name of the table you want to alterADD COLUMN: The action used to add a new column to a tablecolumn_name: The name of the column you want to adddata_type: The data type of the column you want to add
Helpful links
More of Postgresql
- How can I extract the year from a PostgreSQL timestamp?
- How can I create a hierarchical query in PostgreSQL?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL's "zero if null" feature?
- How can I integrate PostgreSQL with Yii2?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I monitor PostgreSQL performance using Zabbix?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I troubleshoot zero damaged pages in PostgreSQL?
See more codes...