jerry
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
product="SurfacePro"
from(u in Product,
where: like(u.product_name, %product%),
select: %{product_id: u.id, description: u.product_desc}
) |> Repo.all
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
Have you taken a look at the documentation? Ecto.Query.API — Ecto v3.14.0
From how I read it, you need to pass in a string as second argument, eg.
like(u.product_name, "%SurfacePro%"), but you wan’t this probably set dynamically at runtime from user input.Since I’m not sure if you are allowed to interpolate a string in the query the way you would do it outside, I’ll prepare it and then pin:
jerry
Hello @NobbZ,
Many thanks.
Your suggestion worked.
I had tried several different options without success.
Regards,
Jerry
rameshsharma
Can someone please guide me here, below is my requirement:-
iex:8> Repo.all(from u in AdminUser, select: u.roles)
This query gives the below result:-
[
[“root”],
[“super”, “transfer”, “operator”],
[“super”, “transfer”, “operator”],
[“super”, “operator”],
[“root”]
]
This is working to get the count for “root” as 2.
Repo.one(from u in AdminUser, where: u.roles == [1], select: count(“*”))
How to get the count of rows with only “super”?
“root” ↩︎
lucaong
Hi @rameshsharma , welcome to the forum!
Yours sounds like a different question than the one in this thread, as it’s not about LIKE/ILIKE queries (or am I mistaken?).
If so, it’s probably better to post it as a separate question, outlining your problem and goals. Some useful info would be:
rolescolumn? Is it a Postgres array of strings?super(and no other role), or rows that includesuperamong the roles?rameshsharma
Hi Luca,
Thanks for responding. I posted here as I thought it could be linked to like search. S.orry for that
The roles column in database is a Postgres array of strings. You are correct.
I want to get the count of rows that include ‘super’ among the roles?
lucaong
I don’t have a computer here to try this right now (I am on my phone now), but if you are selecting for rows that contain
superamong the roles, you should be able to do so with theANY(array)expression. Adapting from your query, something like this (untested):“root” ↩︎
rameshsharma
Sorry Luca, getting error here with this query:-
iex:9> Repo.one(from u in AdminUser, where: fragment(“ANY(roles)”) == “super”, select: count(“*”))
[debug] QUERY ERROR source=“admin_users” db=0.0ms queue=2.3ms idle=1758.9ms
SELECT count(‘*’) FROM “admin_users” AS a0 WHERE (ANY(roles) = ‘super’)
** (Postgrex.Error) ERROR 42601 (syntax_error) syntax error at or near “ANY”
lucaong
Sorry, I am not able to check it now. Maybe you just need to add a space after
ANY, likeANY (roles), or you need to invert the order, like"super" == fragment("ANY(roles)"), or maybe I am just completely off.rameshsharma
You are a genius Luca. Reverting the order works. Thanks for your help.
iex:13> Repo.one(from u in AdminUser, where: “super” == fragment(“ANY(roles)”), select: count(""))
[debug] QUERY OK source=“admin_users” db=1.7ms idle=1958.4ms
SELECT count('') FROM “admin_users” AS a0 WHERE (‘super’ = ANY(roles))
3.
silverdr
Apparently one can pin the interpolated string too