Skip site navigation (1) Skip section navigation (2)

Re: Passing in parameters enclosed in double quotes

From: Federico Di Gregorio <fog(at)dndg(dot)it>
To: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org, Brent Hoover <brent(at)thebuddhalodge(dot)com>
Subject: Re: Passing in parameters enclosed in double quotes
Date: 2011-11-18 16:58:10
Message-ID: 4EC68EA2.5050204@dndg.it (view raw or flat)
Thread:
Lists: psycopg
On 18/11/11 17:43, Adrian Klaver wrote:
> On Friday, November 18, 2011 7:37:32 am Federico Di Gregorio wrote:
>> > On 18/11/11 16:31, Brent Hoover wrote:
[snip]
> I was following along and tried the above and it did not work for me.
> 
> On Postgres end:
> 
> CREATE table "test 1" (id serial, fld_1 text);
> 
> test(5432)aklaver=>\d "test 1"
>                           Table "public.test 1"
>  Column |  Type   |                       Modifiers                       
> --------+---------+-------------------------------------------------------
>  id     | integer | not null default nextval('"test 1_id_seq"'::regclass)
>  fld_1  | text    | 
> 
> 
> 
> test(5432)aklaver=>select pg_get_serial_sequence('"test 1"','id');
>  pg_get_serial_sequence 
> ------------------------
>  public."test 1_id_seq"
> 
> 
> On Psycopg2 end:
> 
> cur.execute("""select pg_get_serial_sequence(%s,%s)""",(AsIs('"test 1"'),'id'))
> ProgrammingError: column "test 1" does not exist
> LINE 1: select pg_get_serial_sequence("test 1",E'id')
> 
> cur.execute("""select pg_get_serial_sequence(%s,%s)""",(AsIs("test 1"),'id'))
> ProgrammingError: syntax error at or near "1"
> LINE 1: select pg_get_serial_sequence(test 1,E'id')
> 
> The only way I could get the substitution to work is:
> cur.execute("""select pg_get_serial_sequence(%s,%s)""",('"test 1"','id'))
> rs=cur.fetchall()
> rs
>  [('public."test 1_id_seq"',)]

Given your example query in psql that's correct.

-- 
Federico Di Gregorio                                       fog(at)initd(dot)org
  "Yes, your honour, I have RSA encryption code tattood on my penis.
   Shall I show the jury?"                                     -- <dark>

In response to

Responses

psycopg by date

Next:From: Adrian KlaverDate: 2011-11-18 17:22:41
Subject: Re: Passing in parameters enclosed in double quotes
Previous:From: Jan UrbańskiDate: 2011-11-18 16:49:42
Subject: Re: Passing in parameters enclosed in double quotes

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group