I would like to use an array comparison in a query, but with each array element being the result of a function. I do this by making the array with:
terms = [func.dmetaphone(t) for t in terms.split()]
When I use this array in a comparison I get an error "can't adapt type 'Function'" because it is passing [<sqlalchemy.sql.expression.Function at 0x1057b8310; dmetaphone>] as the array.
My full query looks like:
terms = [func.dmetaphone(t) for t in terms.split()]
metaphones = Session.query(func.dmetaphone(func.unnest(func.string_to_array(Customer.name, ' '))).label('mphone'), Customer.id).subquery()
.having(func.array_agg(metaphones.columns.mphone).op('<@')(terms))
From all the documentation I have read it this should work, but SQLAlchemy is not evaluating the func.dmetaphone call within the array. Is there a way to force it to do that?
Thanks,
Jason