简体   繁体   English

错误:“ INTEGER”处或附近的语法错误

[英]ERROR: syntax error at or near “INTEGER”

I am using Flyway to migrate PostgreSQL tables for a spring web app and thus, I've written a set of SQL queries which add columns to an existing table, eg : 我正在使用Flyway迁移Spring Web应用程序的PostgreSQL表,因此,我编写了一组SQL查询,这些查询将列添加到现有表中,例如:

ALTER TABLE table_1 ADD COLUMN table_value_x TYPE INTEGER;
ALTER TABLE table_1 ADD COLUMN table_value_y TYPE VARCHAR(100);

After deploying war file on Tomcat, I get the following error : 在Tomcat上部署war文件后,出现以下错误:

ERROR: syntax error at or near "INTEGER" 错误:“ INTEGER”或附近的语法错误

Since Postgre is not so informative about its errors, I am looking for any kind of advice or suggestions on what this might be, thank you. 由于Postgre对其错误的了解并不多,因此我正在寻找有关此问题的任何建议或意见,谢谢。

According to the docs , I believe you need to omit TYPE 根据文档 ,我相信您需要省略TYPE

ALTER TABLE table_1 ADD COLUMN table_value_x INTEGER;
ALTER TABLE table_1 ADD COLUMN table_value_y VARCHAR(100);

From the docs, the TYPE keyword is only used when you are changing the datatype of an existing column. 从文档中,仅当您更改现有列的数据类型时才使用TYPE关键字。

ALTER [ COLUMN ] column [ SET DATA ] TYPE data_type [ COLLATE collation ] [ USING expression ]

The TYPE keyword is only used when changing (altering) the column datatype. TYPE关键字仅在更改(更改)列数据类型时使用。 For adding columns, omit the TYPE keyword, as Matt wrote, and as it is shown here in the examples of the documentation (at the end of the page): https://www.postgresql.org/docs/9.4/static/sql-altertable.html 如Matt所写,要添加列,请省略TYPE关键字,如文档示例中所示(在页面末尾)所示: https : //www.postgresql.org/docs/9.4/static/ sql-altertable.html

I suspect it might work if you get rid of the word 'TYPE'. 我怀疑如果您摆脱“ TYPE”一词可能会起作用。

See example below, from the Postgres site. 请参见Postgres网站上的以下示例。

ALTER TABLE distributors ADD COLUMN address varchar(30);

Edit: I see a whole bunch of people beat me to it. 编辑:我看到一大堆人都击败了我。

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

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