【发布时间】:2020-01-13 13:24:39
【问题描述】:
我想用 psycopg2 添加一列,但我遇到了一个错误,说它无法识别类型。我做错了什么?
这是代码:
alter_query_for_attributes =
"""
ALTER TABLE {schema}.{table}
ADD COLUMN IF NOT EXISTS {sat_attributes} {sat_value};
"""
final_query_attributes = sql.SQL(alter_query_for_attributes).format(
schema = sql.Identifier("testSchema"),
table = sql.Identifier("address"),
sat_attributes=sql.Identifier(sat[0]),
sat_value=sql.Identifier(sat[1])
)
ALTER TABLE "testSchema"."address"
ADD COLUMN IF NOT EXISTS "address_line_1" "varchar(250)";
这给了我错误:
psycopg2.errors.UndefinedObject: type "varchar(250)" does not exist
LINE 12: ... ADD COLUMN IF NOT EXISTS "address_line_1" "varchar(2...
^
【问题讨论】:
-
报错是因为最终的sql查询有双引号中的数据类型。检查这个:dbfiddle.uk/…
标签: python sql postgresql psycopg2