错误:语法错误或接近 “修改” - 在Postgres的
我的Postgres错误:语法错误或接近 “修改” - 在Postgres的
alter table user modify column 'distinguishedName1' text;
和
alter table user modify column distinguishedName1 text;
-
user
执行这条SQL语句是表名 -
distinguishedName1
是具有整数数据类型的列名称。
我想根据用户的输入将数据类型修改为boolean或text或varchar(256)等。但是当我运行查询时出现错误
ERROR: syntax error at or near "modify"
不知道是什么问题。在正确的查询中需要帮助。
试试这个:
ALTER TABLE "user" ALTER COLUMN distinguishedName1 TYPE text USING code::text;
或
ALTER TABLE "user" ALTER COLUMN distinguishedName1 TYPE text
也不要注意的是,使用是可选的。见manual这里:
The optional USING clause specifies how to compute the new column value from the old; if omitted, the default conversion is the same as an assignment cast from old data type to new. A USING clause must be provided if there is no implicit or assignment cast from old to new type.
在一个侧面说明尽量避免命名你的表为reserved keywords。
我不认为这里需要'USING' – sagi
@sagi: - 是的,我已经更新了。 –
查询“alter table user alter column distinguishedName1 type text using distinguishedName1 :: text;对我来说工作正常,但如果我尝试将数据类型更改为整数或布尔值,则相同的查询不起作用。 –
POSTGRES
语法改变列类型:
ALTER TABLE user ALTER COLUMN distinguishedName1 TYPE text;
alter table user Alter column distinguishedName1 text;
语法错误,为SQL Server,你必须使用alter修改表的列
凡[手册中(HTTP: //www.postgresql.org/docs/current/static/sql-altertable.html)你有没有看到修改关键字? –
“*根据用户的输入将数据类型修改为(...)”,这听起来像一个可怕的想法。你想用它解决什么问题? –