简体   繁体   English

Postgres Sql:更改表

[英]Postgres Sql : Alter table

I am fetching all the records from the Excel sheet and adding columns into the database according to the Excel header row.我正在从 Excel 工作表中获取所有记录,并根据 Excel 标题行将列添加到数据库中。 After fetching I alter the table and adding columns into the newly created table and it works perfectly fine.获取后,我更改了表并将列添加到新创建的表中,并且它工作得很好。 but when I add one more column into the excel file and running the query again it supposed to add the column which I have created in the excel file but instead, it gives me an error of Column already exists The query which I m running is但是当我在 excel 文件中再添加一列并再次运行查询时,它应该添加我在 excel 文件中创建的列,但相反,它给了我一个错误Column already exists我正在运行的查询是

"ALTER TABLE " + name + " ADD " + cellValue + " varchar(5000)" "ALTER TABLE" + 名称 + " ADD " + cellValue + " varchar(5000)"

Thanks in advance..提前致谢..

如果您只想创建不存在的列,请像这样编写查询

"ALTER TABLE " + name + " ADD if not exists " + cellValue + " varchar(5000)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM