我正在把数据从postgres移到snowflake。最初它是有效的,但我补充说:
df_postgres["dateutc"]= pd.to_datetime(df_postgres["dateutc"])
因为日期格式不正确地加载到snowflake,现在我看到这个错误:
sql编译错误:错误行1的位置87无效标识符“dateutc”
这是我的密码:
from sqlalchemy import create_engine
import pandas as pd
import glob
import os
from config import postgres_user, postgres_pass, host,port, postgres_db, snow_user, snow_pass,snow_account,snow_warehouse
from snowflake.connector.pandas_tools import pd_writer
from snowflake.sqlalchemy import URL
from sqlalchemy.dialects import registry
registry.register('snowflake', 'snowflake.sqlalchemy', 'dialect')
engine = create_engine(f'postgresql://{postgres_user}:{postgres_pass}@{host}:{port}/{postgres_db}')
conn = engine.connect()
# reads query
df_postgres = pd.read_sql("SELECT * FROM rok.my_table", conn)
# dropping these columns
drop_cols=['RPM', 'RPT']
df_postgres.drop(drop_cols, inplace=True, axis=1)
# changed columns to lowercase
df_postgres.columns = df_postgres.columns.str.lower()
df_postgres["dateutc"]= pd.to_datetime(df_postgres["dateutc"])
print(df_postgres.dateutc.dtype)
sf_conn = create_engine(URL(
account = snow_account,
user = snow_user,
password = snow_pass,
database = 'test',
schema = 'my_schema',
warehouse = 'test',
role = 'test',
))
df_postgres.to_sql(name='my_table',
index = False,
con = sf_conn,
if_exists = 'append',
chunksize = 300,
method = pd_writer)
暂无答案!
目前还没有任何答案,快来回答吧!