[Python-Dev] BLOBs in Pg

Aahz aahz at pythoncraft.com
Thu Apr 9 22:53:26 CEST 2009

On Thu, Apr 09, 2009, Steve Holden wrote:
> import psycopg2 as db
> conn = db.connect(database="maildb", user="@@@", password="@@@",
> host="localhost", port=5432)
> curs = conn.cursor()
> curs.execute("DELETE FROM tst")
> curs.execute("INSERT INTO tst (byt) VALUES (%s)",
>              ("".join(chr(i) for i in range(256)), ))
> conn.commit()
> curs.execute("SELECT byt FROM tst")
> for st, in curs.fetchall():
>     print len(st)
> If I change the date to use range(1, 256) I get a ProgrammingError fron
> PostgreSQL "invalid input syntax for type bytea".
> If I can't pass a 256-byte string into a BLOB and get it back without
> anything like this happening then there's *something* in the chain that
> makes the database useless. My current belief is that this something is
> fairly deeply embedded in the PostgreSQL engine. No "syntax" should be
> necessary.

You're not using a parameterized query.  I suggest you post to c.l.py for
more information.  ;-)
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Why is this newsgroup different from all other newsgroups?

More information about the Python-Dev mailing list