snowflake.connector SQL 编译错误来自 pandas 数据帧的无效标识符
snowflake.connector SQL compilation error invalid identifier from pandas dataframe
我正在尝试将从 json 响应中创建的 df 提取到现有 table 中(table 目前是空的,因为我似乎无法得到这个工作)
df 如下所示 table:
index
clicks_affiliated
0
3214
1
2221
但我看到以下错误:
snowflake.connector.errors.ProgrammingError: 000904 (42000): SQL
compilation error: error line 1 at position 94
invalid identifier '"clicks_affiliated"'
雪花中的列名与我的数据框中的列匹配。
这是我的代码:
import pandas as pd
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine
import snowflake.connector
from snowflake.connector.pandas_tools import write_pandas, pd_writer
from pandas import json_normalize
import requests
df_norm = json_normalize(json_response, 'reports')
#I've tried also adding the below line (and removing it) but I see the same error
df = df_norm.reset_index(drop=True)
def create_db_engine(db_name, schema_name):
engine = URL(
account="ab12345.us-west-2",
user="my_user",
password="my_pw",
database="DB",
schema="PUBLIC",
warehouse="WH1",
role="DEV"
)
return engine
def create_table(out_df, table_name, idx=False):
url = create_db_engine(db_name="DB", schema_name="PUBLIC")
engine = create_engine(url)
connection = engine.connect()
try:
out_df.to_sql(
table_name, connection, if_exists="append", index=idx, method=pd_writer
)
except ConnectionError:
print("Unable to connect to database!")
finally:
connection.close()
engine.dispose()
return True
print(df.head)
create_table(df, "reporting")
所以...原来我需要将数据框中的列更改为 大写
我在创建数据框之后添加了这个并且它起作用了:
df.columns = map(lambda x: str(x).upper(), df.columns)
我正在尝试将从 json 响应中创建的 df 提取到现有 table 中(table 目前是空的,因为我似乎无法得到这个工作)
df 如下所示 table:
index | clicks_affiliated |
---|---|
0 | 3214 |
1 | 2221 |
但我看到以下错误:
snowflake.connector.errors.ProgrammingError: 000904 (42000): SQL compilation error: error line 1 at position 94 invalid identifier '"clicks_affiliated"'
雪花中的列名与我的数据框中的列匹配。
这是我的代码:
import pandas as pd
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine
import snowflake.connector
from snowflake.connector.pandas_tools import write_pandas, pd_writer
from pandas import json_normalize
import requests
df_norm = json_normalize(json_response, 'reports')
#I've tried also adding the below line (and removing it) but I see the same error
df = df_norm.reset_index(drop=True)
def create_db_engine(db_name, schema_name):
engine = URL(
account="ab12345.us-west-2",
user="my_user",
password="my_pw",
database="DB",
schema="PUBLIC",
warehouse="WH1",
role="DEV"
)
return engine
def create_table(out_df, table_name, idx=False):
url = create_db_engine(db_name="DB", schema_name="PUBLIC")
engine = create_engine(url)
connection = engine.connect()
try:
out_df.to_sql(
table_name, connection, if_exists="append", index=idx, method=pd_writer
)
except ConnectionError:
print("Unable to connect to database!")
finally:
connection.close()
engine.dispose()
return True
print(df.head)
create_table(df, "reporting")
所以...原来我需要将数据框中的列更改为 大写
我在创建数据框之后添加了这个并且它起作用了:
df.columns = map(lambda x: str(x).upper(), df.columns)