Quantcast
Viewing all articles
Browse latest Browse all 3

Answer by Nimir for Why are pin operators necessary in Ecto queries?

According to Ecto documentation, the pin operator in ecto is used for query interpolation:

External values and Elixir expressions can be injected into a query expression with ^

def with_minimum(age, height_ft) do  from u in "users",    where: u.age > ^age and u.height > ^(height_ft * 3.28),    select: u.nameend

Trying to skip the pin will give you an error as Ecto cann't figure out a database function or query expression named age:

(Ecto.Query.CompileError) variable age is not a valid query expression. Variables need to be explicitly interpolated in queries with ^


Viewing all articles
Browse latest Browse all 3

Trending Articles