Bryan wrote:
>
> Why can't I refer to a column with query.c at this point?  The query
> already has columns in its c collection, and I don't want to have
> repeat string names of columns, it would be cleaner to say
> query.c.jobId than "jobId".  I thought that query.c.jobId would simply
> generate "jobId" when the sql was generated.


If you had this:

select a from (select sometable.a AS q, 'some value' AS a from sometable)

what does "select a" refer to ?  the "a" column on "sometable"?  or the
phrase 'some value' ?   It's the latter.  It doesn't matter what names
"sometable" defines - the names that the inner SELECT statement "exports"
are independent of that.

The .c collection on a selectable works the same way.   It represents the
"public" names exposed by the selectable unit.   therefore if you had a
table with columns "a" and "b", and your select were:

s = select([table.c.a])

"s" would only have "s.c.a" available, and not "b".   Similarly you might
say:

s = select([table.c.a.label("q"), literal_column("'some value'").label('a')])

where in the same way as the SQL example, s.c.q refers to the column
representing "table.c.a", and s.c.a refers to the "some value" expression.

this pattern remains consistent so that the expression language can work
as consistently as SQL.  For example, you might deal with the table's
column object and the exported column object of a select() at the same
time:

from sqlalchemy.sql import table, column, select

t1 = table('t', column('a'), column('b'), column('c'))

s = select([t1]).where(t1.c.b=='b')
print s

s2 = select([s, t1]).where(s.c.b=='b').where(t1.c.a==s.c.a)
print s2

It would be impossible to produce such a construct if "s.c.a" referred to
"t1.c.a" or if "s.c.b" referred to "t1.c.b".



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to