Re: Re: Problem using dynamic table names with pyformat

Ganesan R <[email protected]>
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
>>>>> "Gerhard" == Gerhard Häring <[email protected]> writes:

> Well, first, SELECT * sucks ;-)

Agreed :-)

> A combination of Python expansion and DB-API quoting should do.

> cursor.execute("SEELCT a, b, c FROM %s WHERE ID=%%s" % table, (25,))

> Note the doubled percent sign to make the Python expansion leave the second
> %s (for the DB-API quoting) alone.

Ahh, that will do the trick, thank you :-). 

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

> In theory, that's true. In reality, PostgreSQL started supporst
> PREPARE/EXECUTE only in 7.3, and we don't automatically use that.

> But you can *explicitely* use PREPARE/EXECUTE with pyPgSQL just fine.

That's good to know. Thanks again.

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