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)
最佳答案
在Snowflake(和SQL:2003)中为SAMPLE
is a reserved keyword,但似乎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")
关于python - 如何修复Snowflake数据库写入错误:雪花.connector.errors.ProgrammingError)001003(42000),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55349047/