query = from p in Post, where: fragment("'?' = ANY (?)", "ecto", p.tags)
value="ecto"query = from p in Post, where: fragment("'?' = ANY (?)", ^value, p.tags)
create table(:post) doadd :tags, {:array, :string}end
It’s not going to work because all interpolated values are translated to SQL query parameters, the fragment will be translated to the SQL '$1' = ANY (p0.tags)
where '$1'
is just a string literal - not a parameter.
The following, without the single quotes should work:
value="ecto"
query = from p in Post, where: fragment("? = ANY (?)", ^value, p.tags)
Ecto’s query syntax support this directly with: from p in Post, where: ^value in p.tags
.
--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/b060fe5e-5e7a-47e8-b24e-ad1bc6f44162%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
SELECT p0."id", p0."tags" FROM "posts" AS p0 WHERE (in($1, p0."tags")) ["elixir"]
I get the error "syntax error at or near "in"" ... anything I'm missing here? I'm running PostgreSQL 9.4.1.
Thanks again,
Thomas
--
You received this message because you are subscribed to a topic in the Google Groups "elixir-ecto" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-ecto/71jID-QjEoo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAM_eapiMs8hnJJPFuDA8SJy_HPBj7JNGe7FRHxq%2BdSJ2uqDY%3DQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CALwVE0pB%2By4J3uaVrXF6XPZRMj9ikG9hqh1oVqa-fEWJB9CSew%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAM_eaphxUf9uOkisCh2b87o4-7zOGaDLpWnifz-N%2Bcau2gEHFA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAGnRm4JnkpgE8D8EfgYkAf48JJ3f43MpJdvBHxSgEG576kvEAQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CALwVE0oGPMxDQckodrDDopam5Y8M-%3D6LwoH5MFYj-erwRXoWLA%40mail.gmail.com.
from p in Post, where: fragment(" '?' = ANY (?)", "ecto", p.tags)
and now this works as well:
val="ecto"
from p in Post, where: fragment(" ? = ANY (?)", ^val, p.tags)
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAGnRm4KBjqRg%3DbfR0j6THBpkNmiBhF8CkwEfUDC5wS%3DCagPBAw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CALwVE0qtW0J5wUsSfOGKL_jb87gX35HXYndgR3tGpq-uqqn4rw%40mail.gmail.com.
from p in Post, where: fragment("? = ANY (?)", ^"ecto", p.tags)
Or:
val="ecto"
from p in Post, where: fragment(" ? = ANY (?)", ^val, p.tags)
Our mistake is in allowing a literal string as argument. I'll fix it in master.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAGnRm4KYfRW8GE%2B%3DBp2-2d%2BrQa99KnTh151vN13YFQG9y_W9Xw%40mail.gmail.com.
from p in Post, where: "ecto" in p.tags
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CALwVE0p7S%3DGZhTAFronaor1aFNEpweAeLtAZ81P%2BKx4qWZVOfA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/5ae3c2cc-2d6d-41c8-80cd-fd86c9606f5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/5ae3c2cc-2d6d-41c8-80cd-fd86c9606f5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.