Ash FrameworkAF
Ash Framework3y ago
8 replies
Blibs

Ash.Query fragment inside a select?

Hello, I'm trying to replicate this query with Ash.Query:

WITH constants (value) AS ( values ('hue') )
SELECT
  id,
  first_name,
  surname,
  email,
  similarity(concat_ws(' ', first_name, surname), value) as sml_full_name
FROM users, constants name
WHERE value <% concat_ws(' ', first_name, surname)
ORDER BY sml_full_name DESC;


Note: Ignore the contants line, that is only to testing.

What I was able to get working is this so far:

Markets.Property.Offeror
|> Ash.Query.filter(fragment("? <% concat_ws(' ', ?, ?)", ^value, first_name, surname))
|> Markets.read!()


What I'm not sure how to do is create that select that will run the similarity function and then use it in my order by.

I believe I probably can get that using calculation, but if possible I would like to have that directly in the query.
Was this page helpful?