Having Column name Error

As is done to call a column that is an alias?

from p in query,
     having: fragment("name ILIKE ?", "%table%"), 
     limit: ^limit,
     select: %{id: p.pd_id, name: fragment("? ||'  '|| ? AS name ", p.descp,  p.code)}

#dipslay error
** (Postgrex.Error) ERROR (undefined_column): no existe la columna «name»
1 Like

Can you show the columns description from the BD?

CREATE TABLE public.repo_products (
  pd_id SERIAL,
  code VARCHAR(20),
  sku VARCHAR(20),
  desc VARCHAR(255),
  price REAL,
  inserted_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
  updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
  CONSTRAINT repo_products_pkey PRIMARY KEY(pd_id)
)

Here you are trying to access a column named name, and yet:

Here you have no columns named name in your schema, do you actually have a column named name or is it supposed to be something else? :slight_smile:

the idea is to concatenate the “desc” and “code” columns put under an alias “named” and do a search

Ahh, in that case trying to match out in a having via a named select in the same query, hmm, don’t think you can, probably have to concat the string within the having fragment between those two columns as you need. Maybe changing the having line to this might work?

having: fragment("(desc || code) ILIKE ?", "%table%"), 

Also, your schema had no column named descp, was that supposed to be desc?

Yes, I was wrong when copying