Re: Encountered an error

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Shaan Repswal <shaun(dot)reapswaal(at)gmail(dot)com>
Cc: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: Encountered an error
Date: 2016-03-10 12:43:56
Message-ID: CA+mi_8aCZO=irYnPrUfTTTHFXPhqcJEhNp4E7iB84KAUKKbKHA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Thu, Mar 10, 2016 at 5:37 AM, Shaan Repswal
<shaun(dot)reapswaal(at)gmail(dot)com> wrote:
> #First make the appropriate column
> cur.execute("""ALTER TABLE inventory
> ADD %s integer DEFAULT NULL;""",
> [x[0].get_text()])
> #Then give that column the appropriate value for the current
> record
> cur.execute("""UPDATE inventory
> SET %s = %s
> WHERE name = %s;""", [x[0].get_text(),
> x[1].get_text(), self.entry_product_name.get_text()])

You cannot use %s to pass a table or field name: %s is only used for the values.

There is still no support for escaping values into identifier names.
There is something in the current master: the function
psycopg2.extensions.quote_ident(), but it hasn't been released yet and
the interface may change before the release.

-- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message Adrian Klaver 2016-03-10 13:02:51 Re: Encountered an error
Previous Message Shaan Repswal 2016-03-10 05:37:29 Encountered an error