python - 如何修复 Snowflake 数据库写入错误:snowflake.connector.errors.ProgrammingError) 001003 (42000)
问题描述
ProgrammingError: (snowflake.connector.errors.ProgrammingError) 001003 (42000): SQL compilation error:
syntax error line 1 at position 13 unexpected 'sample'. [SQL: '\nCREATE TABLE sample (\n\t"Business Address" TEXT\n)\n\n'] (Background on this error at: http://sqlalche.me/e/f405)
已安装必要的软件包:pip install --upgrade snowflake-sqlalchemy
from sqlalchemy import create_engine
engine = create_engine(
'snowflake://{user}:{password}@{account}/SAMPLE_WORK/public?warehouse=****&role=myrole'.format(user='***',password='****',account='*****')
)
df.to_sql('sample', engine, if_exists='replace', index=False)
解决方案
SAMPLE
是 Snowflake(和 SQL:2003)中的保留关键字,但snowflake-sqlalchemy
方言似乎没有正确引用它。一个快速的技巧是将其注入保留字集:
# Before creating the engine etc.
from snowflake.sqlalchemy.base import SnowflakeIdentifierPreparer
# The set uses lower case, though the source set upper.
SnowflakeIdentifierPreparer.reserved_words.add("sample")
推荐阅读
- git - 如何确定 git fixup 提交的目标提交?
- ios - 当使用 iOS 捆绑标识符限制 Google Places API 密钥时,附近的搜索不起作用
- android - 在回收站视图中滚动单元格时,Android 折叠单元格库未正确获取宽度
- php - EC2 用户数据挂在“检查初始化脚本...”ubuntu php
- python - 在 shell 中执行 python 字典键/值作为命令
- amazon-web-services - Amazon EC2 预留实例可以取消并获得退款吗?
- node.js - ldapjs 什么都不返回,但 ldapsearch 工作并且调试日志显示返回了`SearchEntry`
- bash - 为什么交互式 rebase 会打开 VS Code,为什么我不能从终端运行 WebStorm?
- sql - 使用特定值更新特定列
- python - 如何在python中将数据框与分号合并?