删除不起作用的地方
Delete where in does not works
我正在使用 Postres 数据库开发一个项目。
我正在尝试根据 python 列表删除 table 的所有行。
我的代码是:
listofMonths = []
listofMonths = pl.month.unique() # list of months in which there is data to update
deletequery = f'DELETE FROM {table_name} WHERE month IN (' + ','.join((str(n) for n in listofMonths)) + ');'
db.execute(deletequery)
我有一个错误:
删除错误到 table plc (psycopg2.errors.UndefinedFunction) operator does not exist: text = integer
第 1 行:从 plc 中删除月份在 (2020-03-0...
^
提示:没有运算符匹配给定的名称和参数类型。您可能需要添加显式类型转换。
月份栏是文本栏。
我的查询似乎是这样的:
'DELETE FROM plclass123145722922162 WHERE month IN (2020-03-01,2020-01-01,2020-02-01,2020-04-01);'
我确定我需要 ' 值之间但不知道如何解决
谢谢
输出的时候可以用一对单引号把n
括起来:
deletequery = f'DELETE FROM {table_name} WHERE month IN (' + ','.join(f"'{n}'" for n in listofMonths) + ');'
我正在使用 Postres 数据库开发一个项目。 我正在尝试根据 python 列表删除 table 的所有行。
我的代码是:
listofMonths = []
listofMonths = pl.month.unique() # list of months in which there is data to update
deletequery = f'DELETE FROM {table_name} WHERE month IN (' + ','.join((str(n) for n in listofMonths)) + ');'
db.execute(deletequery)
我有一个错误: 删除错误到 table plc (psycopg2.errors.UndefinedFunction) operator does not exist: text = integer 第 1 行:从 plc 中删除月份在 (2020-03-0... ^ 提示:没有运算符匹配给定的名称和参数类型。您可能需要添加显式类型转换。
月份栏是文本栏。
我的查询似乎是这样的: 'DELETE FROM plclass123145722922162 WHERE month IN (2020-03-01,2020-01-01,2020-02-01,2020-04-01);'
我确定我需要 ' 值之间但不知道如何解决
谢谢
输出的时候可以用一对单引号把n
括起来:
deletequery = f'DELETE FROM {table_name} WHERE month IN (' + ','.join(f"'{n}'" for n in listofMonths) + ');'