On 12/01/2015 12:49 PM, Jonathan Vanasco wrote: > I don't think you can get that exact query staying within the ORM's > cross-platform functionality -- I don't think there is anything that can > generate the `::` version of casting... but I think something like this > should produce the same output: > > r = session.query( Device.id, Device.name, Device.details )\ > .filter( sqlalchemy.sql.expression.cast(Device.details, > sqlalchemy.types.String).like('99') )\ > .all() > > I'm doing this from memory, so i could be off -- but the general idea is > that you'll `cast` into a `String`, and then run the `like` operator on > that column. The API docs will have the correct format.
see also the JSON operators which have some built-in text casting stuff: http://docs.sqlalchemy.org/en/rel_1_0/dialects/postgresql.html?highlight=json#sqlalchemy.dialects.postgresql.JSON this is also getting improved in 1.1. > > > That should generate something like : > > + SELECT id,name,details FROM Device WHERE cast(details > as text) LIKE '%99%'; > > Instead of: > > - SELECT id,name,details FROM Device WHERE details::text LIKE '%99%'; > > If you need to use the `details::text` format, you could use a text > literal in the WHERE clause. > see http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#using-textual-sql > > -- > 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 sqlalchemy+unsubscr...@googlegroups.com > <mailto:sqlalchemy+unsubscr...@googlegroups.com>. > To post to this group, send email to sqlalchemy@googlegroups.com > <mailto:sqlalchemy@googlegroups.com>. > 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.