如何在Postgres中的表中添加多个列?


127

如何使用pgadmin3在PostgreSQL的一个查询语句中添加多列?

Answers:


225

试试这个 :

ALTER TABLE table ADD COLUMN col1 int, ADD COLUMN col2 int;

11
您可能要参考后继文档ALTER TABLE [ ONLY ] name [ * ] action [, ... ]postgresql.org
mu太短了,

并设置默认值:ALTER TABLE table ADD COLUMN col1 int default 0, ADD COLUMN col2 text default 'foo';
Brian D

0
ALTER TABLE  IF EXISTS  TABLEname 
add ADD  COLUMN   IF NOT EXISTS  column_name data_type  [column_constraint];

详细查询,其中column_constraints是可选的


1
糟糕...以上两种语法在Redshift中均不起作用:-(我收到错误:ERROR:“或”附近的语法错误,第1行:ALTER TABLE x ADD COLUMN col1 int,ADL COLUMN colX int
Doug P
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.