Return to Snippet

Revision: 35815
at November 14, 2010 02:43 by metoikos


Initial Code
# select distinct author from blogtable where keyword = "dust";


class Blog(SQLObject):
    class sqlmeta:
        table = 'blogtable'

    author = StringCol()
    keyword = StringCol()

Blog.select(Blog.q.keyword=='dust', distinct=True)
Version 2
select = Select(
    [Blog.q.author],
    Blog.q.keyword=='dust',
    distinct=True,
)

sql = connection.sqlrepr(select)

for author in connection.queryAll(sql):
    print author

Initial URL
http://stackoverflow.com/questions/4120165/how-to-translate-this-to-sqlobject-select-distinct-columnname-where/

Initial Description

                                

Initial Title
SQLObject sql to python

Initial Tags
sql, python, convert

Initial Language
Python