Problem using dynamic table names with pyformat

Ganesan R <[email protected]>
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
Hi,

I have an application where the table name is known only at run time. Imagine
something like

cursor.execute("SELECT * FROM %s WHERE id = %s", table, 25)

This doesn't work. pyPgSQL appears to quote all arguments passed via
pyformat which causes a syntax error. I am not sure where this is bug
because the table name is not a SQL parameter.

I then tried

cursor.execute("SELECT * FROM %s WHERE id = %s" % table, 25)

This doesn't work either because the % operator complains about "not enough
arguments for format string". I finally worked around by using 

cursor.execute("SELECT * FROM " + table + " WHERE id = %s", 25)

Is there a syntactically clear alternative?

Ganesan


-------------------------------------------------------
This SF.NET email is sponsored by: FREE  SSL Guide from Thawte
are you planning your Web Server Security? Click here to get a FREE
Thawte SSL guide and find the answers to all your  SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.