Reputation: 151
I'm connecting to a postgres db over SQL Alchemy. In testing COPY works great for appending rows to a local db--it's very fast.
COPY ratings FROM '/path/blah.csv' DELIMITER ',' CSV;
However, what I would like to do is COPY a CSV file over the SQL Alchemy connection into a remote postgres db. PG documentation indicates that something like
COPY ratings FROM STDIN '/path/blah.csv' DELIMITER ',' CSV;
might work. But it doesn't. I've tried a bunch of reasonable variations.
Ideas? Thanks for any help, and my apologies if this question is redundant.
Upvotes: 0
Views: 765
Reputation: 13851
I'm not an expert with SqlAlchemy, but I've used copy_from for a "file like" object (aka stream) many times with Psycopg2. And I think you can specify Psycopg2 dialect in SqlAlchemy. Please see the following documentation for SqlAlchemy and copy_from in Psycopg2.
Again, never done it. Worse case, you might have to get a connection via Psycopg2.
Upvotes: 2