4

I am having this problem when I am trying to copy to AWS redshift. This is the code I am trying to run:

with open('path/to/files, 'rb') as fo:
    cursor.copy_from(fo, 'schema.table', sep=',')
    cursor.commit()

And I encountered the error:

psycopg2.ProgrammingError: syntax error at or near "stdin" 
LINE 1: ...Y schema.table FROM stdin WITH...

I am running python 3.5 with psycopg2. Hope that you guys can help! Thx in advance!

2 Answers 2

8

AWS Redshift is not PostgreSQL, though it supports a subset of PostgreSQL syntax and functionality.

It does not have COPY ... FROM STDIN.

See the manual for how to use COPY on Redshift.

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

3 Comments

Thank you for your help!
@CraigRinger I understand your point and see how COPY is usedfrom a command line or a DB tool (DBeaver, etc), but how do you do a copy to a table from within a python script. What module and syntax would you suggest?
You probably have to use multi-inserts instead, or generate data to upload to s3 and COPY from there. shrug. I don't use Redshift. Maybe you should post a new question and link back to this one?
0

check this solution Python psycopg2 insert NULL in some rows in postgresql table

for insert multiple rows or python dataframe in Redshift

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.