1

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.

1
  • 1
    Did you ever figure out this issue? Commented Aug 15, 2013 at 1:23

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I ended up doing just that. I created a CSV file from a table and used psycopg2.copy_from(...) to insert into the destination postgres table.
Great. I'm glad I could help. FYI, try to always make sure you select an answer. It let's people know in the future that an answer should work for them. Also, gives you points. Unfortunately, I think that many people are reluctant to answer questions for people with really low "reputations" because they don't feel like they will get credit for the answer. Just a bit of advice.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.