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 use PostgreSQL with YAML?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How can I extract the year from a date in PostgreSQL?
- How do I use PostgreSQL's XMIN and XMAX features?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I set the PostgreSQL work_mem parameter?
- How can I set a PostgreSQL interval to zero?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I monitor PostgreSQL performance using Zabbix?
- How can I use PostgreSQL's "zero if null" feature?
See more codes...