How to fix Snowflake database write error: snowflake.connector.errors.ProgrammingError) 001003 (42000)
How to fix Snowflake database write error: 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
is a reserved keyword in Snowflake (and SQL:2003), but it seems that the 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")
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
is a reserved keyword in Snowflake (and SQL:2003), but it seems that the 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")