On Jun 21, 2010, at 7:52 PM, Jon Nelson wrote:

> On Mon, Jun 21, 2010 at 5:55 PM, Michael Bayer <[email protected]> 
> wrote:
>> not a bug, that's the correct behavior.
> 
> Can you explain how it is correct? I asked for two things but I only
> got one. Why should it matter if they happen to be the /same/ thing?

The expression language and result systems target result row columns based on 
name, not position.   Additionally, select() objects are themselves 
"selectable", like a Table, and contain a .c. attribute which provides access 
to its columns clause by name.   Both of these systems would not be possible if 
the construct did not represent names uniquely.

If you'd like the same column to be represented twice in the columns clause, 
you can use labels.   select([table.c.col1.label('a'), table.c.col1.label('b']).

The possibility of multiple result elements with the same name is sometimes 
mentioned as a shortcoming in SQL, in that its not truly "relational" 
(relational tuples require that every element be uniquely named).    
SQLAlchemy's pushing of SQL tuples to be slightly more "relational" helps a 
great deal on the Python side.    In any case, I'm not aware of any use case 
that benefits from having the same name multiple times in a result row.

As far as "I asked for two things", from the select() perspective you only 
asked for one thing, twice - column c1.    We wouldn't make the same critique 
of a set() or dict(), where it's natural that putting the same thing in 
multiple times has no effect - in this case the select() list is mostly like a 
dict.



> 
> In this particular case, I need it for what ultimately becomes an
> insert into (....) select (this, that, theother, col1, col1)
> 
> 
>> On Jun 21, 2010, at 5:35 PM, Jon Nelson wrote:
>> 
>>> I'm encountering a problem with SA 0.6.1
>>> I have a select statement which selects the same column twice (and
>>> some other stuff, too).
>>> However, when the query is run (or printed), the column only shows up once.
>>> This seems like a bug.
>>> 
>>> Example:
>>> 
>>> from sqlalchemy import create_engine, select, Table, Column, INT, MetaData
>>> e = create_engine('sqlite://')
>>> meta = MetaData(bind=e)
>>> t = Table( 'test', meta, Column( 'c1', INT() ) )
>>> meta.create_all()
>>> print select([t.c.c1, t.c.c1])
>>> 
>>> I expected:
>>> 
>>> SELECT test.c1, test.c1
>>> FROM test
>>> 
>>> I got:
>>> 
>>> SELECT test.c1
>>> FROM test
>>> 
>>> --
>>> Jon
>>> 
>>> --
>>> 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.
>>> 
>> 
>> --
>> 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.
>> 
>> 
> 
> 
> 
> -- 
> Jon
> 
> -- 
> 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.
> 

-- 
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