python - Python 脚本中 X LIKE '%T%' 导致“TypeError: dict is not a sequence”时的 SQL 案例
问题描述
我正在尝试在 Python 脚本中对 Redshift DB 运行 SQL 查询。以下导致错误“TypeError:dict is not a sequence”,我不知道为什么。
test1 = """
WITH A AS
(
SELECT *,
CASE WHEN substring(text_value, 0, 4) LIKE ' ' THEN substring(substring(text_value, 0, 4), 3) ELSE substring(text_value, 0, 4) END AS cost_center_id
FROM job_custom_fields
WHERE key = 'cost_center'
)
SELECT job_id,
display_value,
CASE WHEN cost_center_id LIKE '%T%' THEN SUBSTRING(cost_center_id, 1,1)
WHEN cost_center_id LIKE '%D%' THEN SUBSTRING(cost_center_id, 1,1)
WHEN cost_center_id LIKE '%P%' THEN SUBSTRING(cost_center_id, 1,1) ELSE cost_center_id END AS cost_center_id
FROM A
"""
red_engine = create_engine('postgresql+psycopg2://org_525:LZynsTS56PqPlHVhIIgUdDf1c1wuW4gD@redshift.greenhouse.io:5439/greenhouse')
test = pd.read_sql_query(test1,red_engine)
test
非常感谢任何帮助
解决方案
您需要%%
在 python%
中使用,因为您在类似的语句中使用。
%
在python中用于字符串格式化
推荐阅读
- node.js - 如何更新 nodejs 和 npm 版本?
- python - 如何在 GPU 上创建 Theano 共享变量?
- ios - 在 iOS Swift 中将 UIBezierPath 添加到 CAShapeLayer
- css - 如何阻止媒体查询过早触发基本样式?
- node.js - 通过 Child_Process 在 Electron 中安装 Homebrew 作为依赖项
- c# - 为开发环境设置 Azure 搜索
- python - 使用 Docker for windows 从 Python 脚本创建 docker 映像时无法获取包含数据的输出文件
- android - 我无法应用自定义脚本插件
- deployment - pycharm 版本控制和部署
- python - 烧瓶 g 对象是否有超时?