ERROR: syntax error at or near "modify" - in postgres
ERROR: syntax error at or near "modify" - in postgres
我在 Postgres 中执行了这条 SQL 语句
alter table user modify column 'distinguishedName1' text;
和
alter table user modify column distinguishedName1 text;
user
是 table 名字
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
另请注意,USING 是可选的。请在此处查看 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.
POSTGRES
改变列类型的语法:
ALTER TABLE user ALTER COLUMN distinguishedName1 TYPE text;
alter table user Alter column distinguishedName1 text;
语法错误,对于sql服务器你必须使用alter来修改table
的列
我在 Postgres 中执行了这条 SQL 语句
alter table user modify column 'distinguishedName1' text;
和
alter table user modify column distinguishedName1 text;
user
是 table 名字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
另请注意,USING 是可选的。请在此处查看 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.
POSTGRES
改变列类型的语法:
ALTER TABLE user ALTER COLUMN distinguishedName1 TYPE text;
alter table user Alter column distinguishedName1 text;
语法错误,对于sql服务器你必须使用alter来修改table
的列