psycopg2.ProgrammingError: syntax error at or near "stdin" error when trying to copy_from redshift

psycopg2.ProgrammingError: syntax error at or near "stdin" error when trying to copy_from redshift

我在尝试复制到 AWS redshift 时遇到了这个问题。 这是我正在尝试的代码 运行:

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

我遇到了错误:

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

我 运行宁 python 3.5 与 psycopg2。 希望你们能帮忙!提前致谢!

A​​WS Redshift 不是 PostgreSQL,尽管它支持 PostgreSQL 语法和功能的一个子集。

没有COPY ... FROM STDIN.

请参阅 the manual 了解如何在 Redshift 上使用 COPY

检查这个解决方案

用于在 Redshift

中插入多行或 python 数据帧