psycopg NULL

Dave Brueck dave at pythonapocrypha.com
Wed Feb 18 16:14:05 EST 2004


Lee wrote:
> > If it is 'pyformat' (Like MySQLdb), then this might work:
> >
> > curs.execute('INSERT INTO foo (i) VALUES (%s)' , None)
> > curs.execute('INSERT INTO foo (i) VALUES (%d)' , None)
> > curs.execute('INSERT INTO foo (i) VALUES (%i)' , None)
> > conn.commit()
> >
> > note: all I did was replace the %'s with commas
> >
> 
> That gives a syntax error ... but it is close!
> 
> 
> vars = {'i': None, 'x': 2, 'y': 1, 'z': None}
> curs.execute('INSERT INTO foo (i) VALUES (%(i)s)', vars)
> conn.commit()
> 
> 
> With the pyformat paramstyle we need the %(varname)s style.

Lee, I think the following will work as well:

curs.execute('INSERT INTO foo (i) VALUES (%s)', (None,))

(passing in a tuple of arg values)

-Dave




More information about the Python-list mailing list