Re: UPDATE command

From: Jonathan Rogers <jrogers(at)emphasys-software(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Re: UPDATE command
Date: 2017-07-21 19:36:37
Message-ID: b08aa25f-cda7-346a-c497-d7bec8b933d8@emphasys-software.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 07/21/2017 12:24 PM, Graeme Gemmill wrote:
> I wish to issue an UPDATE command to update 4 columns of a row that has
> a unique primary key vindex:
>
> SQL = "UPDATE contact SET firstname, addnlnames, surname, rev WHERE
> vindex =? (%s, %s, %s, %s);"
> data = (.......)
> cursor.execute(SQL, data)
>
> How is the value of vindex specified? Is my ? to be replaced by %s where
> the value of vindex is the first of the data values?

It seems you may be confused about both SQL syntax and psycopg2's
handling of parameters. Start with the Posgtgres documentation about the
UPDATE statement:

https://www.postgresql.org/docs/9.6/static/sql-update.html

As explained in its documentation, "%s" is the psycopg2 placeholder. The
SQL string you should pass to pyscopg2 is "UPDATE contact SET firstname
= %s, addnlnames = %s, surname = %s, rev =% WHERE vindex = %s".

http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries

--
Jonathan Rogers
Socialserve.com by Emphasys Software
jrogers(at)emphasys-software(dot)com

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2017-07-22 00:26:23 Re: Fetching data from binary cursor
Previous Message Tom Kazimiers 2017-07-21 18:49:20 Fetching data from binary cursor