Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#24 order by fails for aliases column names

open
nobody
None
5
2003-10-07
2003-10-07
Phil Schwartz
No

Executing the following valid SQL using Gadfly fails:

SELECT COUNT(*) AS num_orders
FROM orders
ORDER BY num_orders

The exceptions thrown are:

File
"/usr/lib/python2.2/site-packages/gadfly/database.py",
line 366, in execute
cs[i] = cs[i].relbind(database)
File
"/usr/lib/python2.2/site-packages/gadfly/semantics.py",
line 2576, in relbind
ob = relbind_sequence(ob, attbindings, db)
File
"/usr/lib/python2.2/site-packages/gadfly/semantics.py",
line 936, in relbind_sequence
result[i] = result[i].relbind(dict,db)
File
"/usr/lib/python2.2/site-packages/gadfly/semantics.py",
line 619, in relbind
return Class(self.thing.relbind(dict,db))
File
"/usr/lib/python2.2/site-packages/gadfly/semantics.py",
line 1050, in relbind
raise NameError, `name` + ": unknown or ambiguous"
NameError: 'NUM_ORDERS': unknown or ambiguous

Similarly, without the aggregate function (COUNT in
this case) the ORDER BY still fails:

SELECT page AS pages
FROM log
ORDER BY pages

(results in the same series of exceptions)

This error seems repeatable irregardless of
table/columns used as long as the ORDER BY contains an
aliases column (or aliased aggregate function, such as
SUM or COUNT, etc)

Discussion

  • Aaron Watters
    Aaron Watters
    2003-10-08

    Logged In: YES
    user_id=1761

    Thanks for the bug report.
    A work around is to use

    SELECT page AS pages
    FROM log
    ORDER BY 1

    for now. -- Aaron Watters