[storm] Query using count

akira nhytro-python at web.de
Wed Aug 8 20:35:13 BST 2007


Thanks Chrisopher, that did the trick, but it seems that the expression 
is still wrong, this is the traceback:

    test= store.execute(expr)
  File 
"C:\Python24\Lib\site-packages\storm-0.9-py2.4.egg\storm\store.py", line 
60, in execute
  File 
"C:\Python24\Lib\site-packages\storm-0.9-py2.4.egg\storm\database.py", 
line 136, in execute
  File 
"C:\Python24\Lib\site-packages\storm-0.9-py2.4.egg\storm\databases\postgres.py", 
line 131, in _raw_execute
  File 
"C:\Python24\Lib\site-packages\storm-0.9-py2.4.egg\storm\database.py", 
line 125, in _raw_execute
psycopg2.ProgrammingError: syntax error at or near "GROUP"
LINE 1: ...ft >= _4.lft AND _5.lft <= _4.rgt ORDER BY _5.lft GROUP BY _...

I´ll post my class and schema since I have had this problem for weeks now:

from storm.locals import *
from storm.info import ClassAlias
from storm.expr import Count
from storm.locals import SQL
from itertools import groupby

class Link(object):
    __storm_table__ = "links"
    id = Int(primary=True)
    name = Unicode()
    title = Unicode()
    link = Unicode()
    lft = Int()
    rgt = Int()


all = ClassAlias(Link)
parent = ClassAlias(Link)
node = ClassAlias(Link)

Thanks!


Christopher Armstrong wrote:
> On 8/8/07, akira <nhytro-python at web.de> wrote:
>   
>> columns = (parent.link, Count()-1)
>> where = And(node.lft > parent.lft, node.lft < parent.rgt)
>> expr = Select(columns, where, order_by=node.lft)
>>
>> test = SQL(("%s") % expr)
>>
>> this gives me this:
>>
>> <storm.expr.SQL object at 0x009F0230>
>>
>> Which is not a result set, does this have to be executed?
>>     
>
> You probably don't want to pass that expression to 'SQL'. Just pass it
> to store.execute (without stringifying it). store.execute(expr)
>
>   




More information about the storm mailing list