Posted By

metoikos on 11/14/10


Tagged

sql python convert sqlobject


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

gartenstuhl


SQLObject sql to python


 / Published in: Python
 

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

  1. # select distinct author from blogtable where keyword = "dust";
  2.  
  3.  
  4. class Blog(SQLObject):
  5. class sqlmeta:
  6. table = 'blogtable'
  7.  
  8. author = StringCol()
  9. keyword = StringCol()
  10.  
  11. Blog.select(Blog.q.keyword=='dust', distinct=True)
  12. Version 2
  13. select = Select(
  14. [Blog.q.author],
  15. Blog.q.keyword=='dust',
  16. distinct=True,
  17. )
  18.  
  19. sql = connection.sqlrepr(select)
  20.  
  21. for author in connection.queryAll(sql):
  22. print author

Report this snippet  

You need to login to post a comment.