[DB-SIG] PyGresSql help

Cary Collett Cary Collett <cary@ratatosk.org>
Tue, 25 Jan 2000 08:19:44 -0600


Thus spake Tom Bryan (tbryan@server.python.net):

> 
> 
> On Mon, 24 Jan 2000, Jim Johannsen wrote:
> 
> > I am trying to use PyGresSQL to connect Python and Postgress.   I have
> > managed to connect to the db, but cannot update the database with a list
> > or with strings.  I have tried the following code w/o success:
> > 
> > cnx.query("INSERT INTO county VALUES(%s,%s,%s)")  %(Ldata[0], Ldata[1],
> > Ldata[3])
> 
> So, I'd suggest the following.  (Note that the whitespace isn't really
> necessary: I'm just trying to emphasize how the parentheses nest.)
> 
> cnx.query (
>     "INSERT INTO county VALUES(%s,%s,%s)" % (
>         Ldata[0], Ldata[1],Ldata[3]
>     ) 
> )
> 

I don't use PostgreSQL, but every other DB I've used will
expect single quotes around strings:

cnx.query (
    "INSERT INTO county VALUES('%s','%s','%s')" % (
        Ldata[0], Ldata[1],Ldata[3]
    ) 
)


Cary

-- 
Cary Collett                                               cary@ratatosk.org
http://ratatosk.org/~cary

"To me boxing is like ballet, except that there's no music, no choreography,
and the dancers hit eachother." -- Jack Handy