psycopg NULL
Lee Harr
missive at frontiernet.net
Wed Feb 18 13:17:49 EST 2004
On 2004-02-18, Ross M Karchner <ross at karchner.com> wrote:
> What is the value of psycopg.paramstyle ?
>
> You probably have to follow the paramstyle format to get the automatic
> translation between Python None to SQL Null.
>
> http://www.python.org/peps/pep-0249.html
>
A ha! Thanks for that link...
> 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.
Thanks for your help.
More information about the Python-list
mailing list