On Nov 13, 2011, at 8:29 PM, Hanss wrote:

> Hello,
> 
>     I'm trying to get the name of the columns of my tables, writing
> 
> columnDb = self.table.__table__.columns._all_cols
> 
> self.labels = [col.name for col in columnDb]
> 
> ColumnDb is a Set Type... and it usually returns all the columns in
> the same order defined in the table...but not always. Is not possible
> to force the order always in the same way for all the tables?

First off, _all_cols is private.  You know this because it starts with an 
underscore, and in this case is also only referenced within ColumnCollection 
internally and not part of any documentation.    Never rely on private 
variables, especially when unnecessary.  Sets in Python are not ordered.

The columns in a Table can be iterated in the order in which they were added 
based on the ".c." collection directly:

        self.labels = [col.name for col in table.c]

this is from 
http://www.sqlalchemy.org/docs/core/schema.html#accessing-tables-and-columns

When using Declarative, the order ultimately comes from the order in which each 
Column object was generated, which drives the order in which Declarative adds 
them to the Table which is then what you get when you iterate over Table.c.





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

Reply via email to