Using MySQL. I was missing the 'func' attribute syntax for calling this in 
my attempts. Works as desired.

Thanks!

Greg--





On Monday, December 28, 2015 at 9:19:22 PM UTC-6, Michael Bayer wrote:
>
> if you're using Postgresql you'd want to look into replace(): 
> http://www.postgresql.org/docs/9.3/static/functions-string.html 
>
> e.g. 
>
> query.filter(func.replace(MyClass.column, ' ', '_') == 'some_other_value') 
>
> though if 'someothervalue' is an in-Python value and your database 
> doesn't have underscores already, you might be able to get away with 
> just using Python replace on that side, converting from underscore to 
> space. 
>
>
> On 12/28/2015 04:29 PM, Horcle wrote: 
> > Looking for something to mimic the replace function in an SQL statement, 
> > like: 
> > 
> > Select * from Clinical where replace(Clinical.string_value, ' ' , '_') 
> > 
> > 
> > On Monday, December 28, 2015 at 11:49:38 AM UTC-6, Horcle wrote: 
> > 
> >     I am iteratively building a complex query. For one step, I have 
> > 
> >     a[i] = 
> a[i].filter(Clinical.string_value.op('=')([value[i]])).subquery() 
> > 
> > 
> >     I would like to simply just replace the value in Clinical.string 
> >     value such that all spaces are turned into underscores. My naive 
> >     approach is to do this as 
> > 
> >     replace(Clinical.string_value, ' ', '_'), but I know the syntax is 
> >     invalid in this context. How do I plug this into my SQLAlch 
> >     statement? I found the replace method 
> >     here: 
> http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.func
>  
> >     <
> http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.func>,
>  
>
> >     but it does not seem to fit my use case. 
> > 
> >     Thanks in advance! 
> > 
> >     Greg-- 
> > 
> > -- 
> > 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:> 
> > <mailto:[email protected] <javascript:>>. 
> > To post to this group, send email to [email protected] 
> <javascript:> 
> > <mailto:[email protected] <javascript:>>. 
> > Visit this group at https://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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to