On Mar 14, 2012, at 7:50 AM, Ronan Dunklau wrote:

> Hello.
> 
> I'd like to append a column clause to a select, or replace an existing
> column if one exists with the same key.
> 
> I've seen that ColumnCollection has a convenient 'replace' method, but I
> don't know how to achieve that with a select instance.
> 
> I can achieve what I want with the following code:
> 
> columns_dict = OrderedDict((col, key) for col in my_select._raw_columns))
> columns_dict['mycol'] = mynewcol
> my_select.raw_columns = columns_dict.values()
> my_select._reset_exported.
> 
> But surely there must be something easier/not involving protected
> attributes ?

select() has a method with_only_colunms() for this purpose:

http://docs.sqlalchemy.org/en/latest/core/expression_api.html#sqlalchemy.sql.expression.Select.with_only_columns


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