我想使用POLARS将地块文件中的数据框存储到PostgreSQL中,代码如下:
def store_in_postgresql(df):
password = 'anon'
username = 'postgres'
database = 'nyc_taxis'
uri = f'postgresql://{username}:{password}@localhost:5432/{database}'
engine = create_engine(uri)
common_sql_state = "SQLSTATE: 42P07"
try:
df.write_database(table_name, connection=uri,
engine='adbc', if_exists='replace')
print('loading has been completed!')
except Exception as e:
if(common_sql_state in str(e)):
df.write_database(table_name, connection=uri,
engine='adbc', if_exists='append')
print('loading has been completed!')
else:
print(e)
但我得到了这样的错误:
INVALID_ARGUMENT: [libpq] Failed to execute COPY statement: PGRES_FATAL_ERROR ERROR: COPY file signature not recognized
. SQLSTATE: 22P04
代码存储小尺寸的数据帧,如400万行(200mb),但当我想存储1800万行(500mb)的 Big Data 帧时,我得到了上面的错误,有没有方法修复代码或可能切片数据帧以将其存储在数据库中?提前谢谢你.