Re: [Sqlalchemy-tickets] [sqlalchemy] #1068: render 'SELECT foo() AS x .. ORDER BY x' by default
Brought to you by:
zzzeek
From: sqlalchemy <mi...@zz...> - 2008-05-31 23:25:02
|
#1068: render 'SELECT foo() AS x .. ORDER BY x' by default --------------------------------+------------------------------------------- Reporter: jek | Owner: zzzeek Type: enhancement | Status: new Priority: high | Milestone: 0.5.0 Component: sql | Severity: no triage selected yet Resolution: | Keywords: Status_field: awaiting triage | --------------------------------+------------------------------------------- Old description: > If an expression present in the select list is used elsewhere in the > query (WHERE, ORDER BY, GROUP BY, etc.), render it as the column name > (label) by default. Unlabeled non-column expressions re-used in ORDER BY > can be rendered positionally as integers. Oracle can override and render > expanded expressions. New description: If an expression present in the select list is used elsewhere in the query (ORDER BY, GROUP BY, etc.), render it as the column name (label) by default. Unlabeled non-column expressions re-used in ORDER BY can be rendered positionally as integers. Oracle can override and render expanded expressions. Comment (by jek): strings seem to work already with the caveat that you need to do your own quoting on reserved identifiers. or were you suggesting something smarter that does column inspection and quoting? i'm thinking maybe like this w/ basic reused references: (Postgres/Firebird) {{{ >>> cl = func.char_length('abc').label('cl') >>> print select([cl]).where(cl > 2).group_by(cl).having(cl > 2).order_by(cl) SELECT char_length('abc') AS cl WHERE char_length('abc') > 2 GROUP BY cl HAVING char_length('abc') > 2 ORDER BY cl }}} sqlite (alone?) supports 'cl' in WHERE. mysql and sqlite will both use 'cl' in HAVING, pg & firebird won't. -- Ticket URL: <http://www.sqlalchemy.org/trac/ticket/1068#comment:2> sqlalchemy <http://www.sqlalchemy.org/> The Database Toolkit for Python |