Unfortunately for me, my actual application's text() clause is a larger, 
more complex bit of sql.  I know it's not ideal, but is there a way to wrap 
the existing TextClause without having to build the whole expression 
programmatically?  E.g. wrap/coerce the TextClause into a ColumnElement; or 
some constructor that inherits from ColumnElement but accepts arbitrary sql 
like text()?

On Saturday, July 18, 2015 at 9:00:11 PM UTC-4, Michael Bayer wrote:
>
>  
>
> On 7/18/15 12:35 PM, Eli Collins wrote:
>  
> Hi All -
>
> I'm currently trying to use sql.union() to construct a union of 
> sql.select() instances.  My problem is that one of the columns in one of 
> the selects is an expression that takes a bind parameter, which is causing 
> an error.
>
> I initially tried to code things as follows ...
>
>  from sqlalchemy.sql import *
>
> s1 = select([text("(:value || c3) as c1").bindparams(value='foo'),
>              column("c2")], from_obj=table("t1"))
> s2 = select([column("c1"), column("c2")], from_obj=table("t2"))
>
> u1 = union(s1, s2)
>
>  
> ... however, union() throws* 'Argument Error: All selectables passed to 
> CompoundSelect must have identical numbers of columns'.*
>
> Tracking this down, the problem seems to be that the first column of s1 is 
> a text() object, which doesn't get counted as a column when union() tries 
> to compare the column counts of the two select() clauses.
>
> I've tried using literal_column(), but it doesn't support passing in a 
> text() element as it's value, nor does it have a bindparams() method. 
>  
>
> use (bindparam("value", String)  + column("c2")).label("c1")
>
>
>  
> I've run out of ideas for how to provide something "column-like" for 
> union(), while at the same time safely use bindparams() to pass in a 
> value.  
>
> I'm not sure if this is a bug, or if there's another construction I should 
> be using.
>
> - Eli Collins
>
> (P.S. I'm using SQLAlchemy 1.0.6; Python 2.7)
>
>
>  -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] 
> <javascript:>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to