Thank you, I did not think of with_only_columns for the last part.

The part that bother me the most is how to build the column list.

I rewrote my code to only use "public" attributes and methods:

columns = ColumnCollection(*myselect.inner_columns)
columns.replace(my_column)
myselect.with_only_columns(columns)

It feels very verbose for what it is. Is this a common use case, worth
a 'generative' helper method on the select ?

For example:

myselect = myselect.replace_column(mycolumn)


On Mar 14, 8:27 pm, Michael Bayer <[email protected]> wrote:
> 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#sqlalch...

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