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

Passing in parameters enclosed in double quotes

From: Brent Hoover <brent(at)thebuddhalodge(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Passing in parameters enclosed in double quotes
Date: 2011-11-18 15:31:14
Message-ID: CAJytaR5CSBNz6JUu=wxV7_D22T2Y=m66d8y2fT3MEPCq0hvyPw@mail.gmail.com (view raw or flat)
Thread:
Lists: psycopg
Hello,

I am sure this is in the documentation somewhere, but I am stumped as to
where.

I am trying to pass in a table name to reset a series of sequences.

conn_cursor.execute("""SELECT setval(pg_get_serial_sequence("%s", %s), 1,
false);""", ( _column[0]), _column[1],))

where _column[0] is a table name, and _column[1] is a column name. So the
table name needs to be directly enclosed in double-quotes, but the psycopg2
adapter is adding single quotes inside that. So instead of getting
"table_name" I get "'table_name'" which does not work. I feel like is
probably an issue of escaping the quotes somehow but I cannot figure out
how. Psycopg2's behavior is completely correct here, it sees a string and
wraps it in quotes, but this case of wanting to access a table name is
somewhat of a special case.

Thanks so much for such a great piece of software.


*Brent Hoover*
Computer Scientist

Responses

psycopg by date

Next:From: Federico Di GregorioDate: 2011-11-18 15:37:32
Subject: Re: Passing in parameters enclosed in double quotes
Previous:From: Federico Di GregorioDate: 2011-11-17 14:34:13
Subject: Re: RFC: Extend psycopg2.connect to accept all valid parameters?

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