With this in a file bug.py:
import sys
import psycopg2
DSN = "host={0} dbname={1} user={2} password={3} port={4} sslmode={5}"
dsn = DSN.format("host", "db", "user", "****", 5432, "prefer")
dbconn = psycopg2.connect(dsn)
for line in sys.stdin:
c = dbconn.cursor()
c.execute(line)
c.close()
dbconn.close()
print sys.argv[0], "done"
sys.exit(0)
And this in load.sql
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (id integer);
This works:
$ cat load.sql | python bug.py
However, putting the following in load.sql segfaults the Python
interpreter:
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (id integer);
COPY foo FROM STDIN;
1
2
3
4
5
6
\.
Maybe what I am doing in the second case is not allowed (if I
perform similar things, but with the copy_from method on the cursor
it works ok), but the above should definitely not segfault the
Python interpreter.
Tested with Python 2.7.3 and a fresh psycopg2 2.5.3 installation
in a virtualenv.