On Mon, Nov 08, 2010 at 09:53:26PM +0000, AlexB wrote:
> I have a specific SQL query that I need:
>
> select distinct author from blogtable where keyword = "dust";
One cannot select a column using the high-level SQLObject API, one can
only select all columns at once (*), and it's almost meaningless to query
select distinct *
SQLBuilder is the mid-level API. To use SQLBuilder first construct the
query:
from sqlobject.sqlbuider import Select
query = Select([BlogTable.q.author], where=BlogTable.q.keyword=='dust', distinct=True)
and then convert the object to SQL query string and execute the string
using the low-level API:
rows = connection.queryAll(connection.sqlrepr(query))
The result is a list of rows, every row is a tuple of length 1 (the
author):
for row in rows:
author = row[0]
print author
Oleg.
--
Oleg Broytman http://phd.pp.ru/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|