Hello!
I'm trying to insert values into a bytea column using the DB-API 2.0
interface of PyGreSQL. The table is declared as
CREATE TABLE foo (foo BYTEA);
and i tried the following approaches:
curs.execute("INSERT INTO foo VALUES (%s)", ["\\"])
curs.execute("INSERT INTO foo VALUES (%s)", [pgdb.Binary("\\")])
Both gave an database error:
DatabaseError: error 'ERROR: invalid input syntax for type bytea
' in 'insert into lars_bytea values ('\\')'
But if I use pgdb.escape_bytea, too much is quoted:
curs.execute("INSERT INTO foo VALUES (%s)", [pgdb.escape_bytea("\\")])
inserts two \ instead of a single one into the database:
curs.execute("select * from lars_bytea");
print pgdb.unescape_bytea(curs.fetchall()[0][0])
outputs two backslashes.
curs.execute("INSERT INTO foo VALUES (E'%s')" % pgdb.escape_bytea("\\"))
works, but becomes ugly, if I use more then one parameter (and now I'm
responsible again for correct quoting for security).
So what's the correct approach to insert bytea values into the database?
- Lras.
_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql