[DB-SIG] inserting strings into postgres db using pgdb (escaping
quotes automagically)
Bryan Lawrence
b.n.lawrence at rl.ac.uk
Wed Jun 18 14:25:15 EDT 2003
Hi Folks
I'm just playing at a common db core module for an application. It works ok
with gadfly and mysql, and I'm trying to extend it to postgresql.
I'm using the pgdb module ...
At the moment (mysql) I do inserts with something like
data=('a',"b's")
cmd="insert into table blah (x,y) values (%s%s)"
self.cursor.execute(cmd,data)
(replacing the %s with ? for gadfly).
This breaks with postgres ...
I tried something like
cmd='insert into table blah (x,y) values (string.join(
map(lambda x: repr(x),data),','))
but that breaks with
ERROR: Attribute ... not found
Clearly I can muck around parsing strings and escaping things, but
that seems remarkably clumsy, and I can't believe I'm the only person with
this problem. I've had a google and rummaged in the manuals, but obviously
didn't turn over the right leaf ... how does one do this with postgres?
I'm not on the mailing list, so if you can help, could you please reply
directly? It's not an easy thing to search for in the archive, so apologies
if this is a much rehearsed problem.
Thanks
Bryan
More information about the DB-SIG
mailing list