Re: Problem using dynamic table names with pyformat

Ganesan R <[email protected]>
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
On Thu, Feb 13, 2003 at 11:02:36PM -0800, Bob Terek wrote:
> 
> > 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
> >
> > Is there a syntactically clear alternative?
> 
> The % operator expects a tuple, so this should work:
> 
> cursor.execute("SELECT * FROM %s WHERE id = %s" % (table, 25))
> 
> but I haven't tried it of course.

That works. But that will disable cursor optimization. From the DB-API-2.0
specification for cursor.execute():

A reference to the operation will be retained by the
cursor.  If the same operation object is passed in again,
then the cursor can optimize its behavior.  This is most
effective for algorithms where the same operation is used,
but different parameters are bound to it (many times).

Ganesan

-- 
Ganesan R


-------------------------------------------------------
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.