sql - COPY data from S3 to RedShift in python (sqlalchemy) -
i'm trying push (with copy) big file s3 redshift. im using sqlalchemy in python execute sql command looks copy works if preliminary truncate table.
the connection works ok:
from sqlalchemy import create_engine engine = create_engine('postgresql://xxxx:xxxx@xxxx:xxxx/xxxx')
with command string (if truncate table before copy command)
toredshift = "truncate table public.my_table; copy public.my_table 's3://xxxx/part-p.csv' credentials 'aws_access_key_id=aaaaaaa;aws_secret_access_key=bbbbbbb' gzip removequotes ignoreheader 0 delimiter '|';" engine.execute(toredshift)
if remove "truncate table public.my_table;" bit
toredshift = "copy public.my_table 's3://xxxx/part-p.csv' credentials 'aws_access_key_id=aaaaaaa;aws_secret_access_key=bbbbbbb' gzip removequotes ignoreheader 0 delimiter '|';" engine.execute(toredshift)
but command works in other sql client (like dbeaver example)
thank ilja. command works:
engine.execute(text(toredshift).execution_options(autocommit=true))
i don't know why able push data truncate bit @ front of string.
ivan
Comments
Post a Comment