psycopg NULL

Lee Harr missive at frontiernet.net
Wed Feb 18 13:25:22 EST 2004


>> 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.
>


Actually, the other way works too, if the 2nd parameter is
a sequence.

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


Thanks again.




More information about the Python-list mailing list