Bugs item #1670239, was opened at 2007-02-27 18:37
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1670239&group_id=74338
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: General
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Vladimir Chukharev (chukharevv)
Assigned to: Nobody/Anonymous (nobody)
Summary: orderBy='..' conflicts with distinct=True in select()
Initial Comment:
I tried to execute select() with parameters orderBy
and distinct for inheritable tables.
Any of the two parameters can be used alone, but if
they are used together, an error occurs.
The following example is printed in Python shell:
from datetime import datetime
from sqlobject import *
from sqlobject.sqlbuilder import *
from sqlobject.inheritance import InheritableSQLObject
sqlhub.processConnection = connectionForURI('postgres:///test')
class Base(InheritableSQLObject):
created = DateTimeCol(default=DateTimeCol.now())
class BaseSample(Base):
name = StringCol(length=40, alternateID=True)
BaseSample.createTable(ifNotExists=True)
Base.createTable(ifNotExists=True)
sample = BaseSample(name='Sample1')
order=BaseSample.q.created
Two working calls of select().
print list(BaseSample.select(orderBy=order))
[<BaseSample 1L name='Sample1' created='datetime.datetime...)'>]
print list(BaseSample.select(distinct=True))
[<BaseSample 1L name='Sample1' created='datetime.datetime...)'>]
Now the error.
print list(BaseSample.select(orderBy=order, distinct=True))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1860-py2.4.egg/sqlobject/sresults.py", line 155, in __iter__
return iter(list(self.lazyIter()))
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1860-py2.4.egg/sqlobject/sresults.py", line 163, in lazyIter
return conn.iterSelect(self)
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1860-py2.4.egg/sqlobject/dbconnection.py", line 364, in iterSelect
select, keepConnection=False)
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1860-py2.4.egg/sqlobject/inheritance/iteration.py", line 10, in __init__
super(InheritableIteration, self).__init__(dbconn, rawconn, select, keepConnection)
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1860-py2.4.egg/sqlobject/dbconnection.py", line 704, in __init__
self.dbconn._executeRetry(self.rawconn, self.cursor, self.query)
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1860-py2.4.egg/sqlobject/dbconnection.py", line 298, in _executeRetry
return cursor.execute(query)
psycopg.ProgrammingError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
SELECT DISTINCT base_sample.id, base_sample.child_name, base_sample.name FROM base, base_sample WHERE ((1 = 1) AND ((base_sample.id) = (base.id))) ORDER BY base.created
Additional information.
SQLObject-0.7.1dev_r1860
TurboGears-1.0b1
Ubuntu
$ uname -a
Linux svetlana-desktop 2.6.15-28-amd64-generic #1 SMP PREEMPT Thu Feb 1 15:53:41 UTC 2007 x86_64 GNU/Linux
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1670239&group_id=74338
|