Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
How to search by array values in PostgreSQL query

I have an array: ARRAY['one','mon','uuuu','wed','thu','fri','qwer'] and query:

select * from table t where t.name like ARRAY[i]

how could I iterate query with ARRAY values and save results into some output?

I mean to get results of:

select * from table t where t.name like 'one'
select * from table t where t.name like 'mon'
select * from table t where t.name like 'uuuu'
...
select * from table t where t.name like 'qwer'

and save them for example into the output

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

One option is to unnest the array in a subquery or CTE and apply the expression you want, e.g.

CREATE TEMPORARY TABLE t (name text);
INSERT INTO t VALUES ('mon'),('qwer'),('mon'),('xpto');

WITH j (val) AS (
 SELECT UNNEST(ARRAY['one','mon','uuuu','wed','thu','fri','qwer'])
) SELECT * FROM j,t WHERE t.name LIKE j.val;

 val  | name 
------+------
 mon  | mon
 mon  | mon
 qwer | qwer
(3 Zeilen)

If you need to use % in your LIKE, just concatenate it to the string with ||, e.g.

WITH j (val) AS (
 SELECT UNNEST(ARRAY['one','mon','uuuu','wed','thu','fri','qwer'])
) SELECT * FROM j,t WHERE t.name LIKE '%' || j.val || '%';

Or use the ANY operator

SELECT * FROM t 
WHERE name LIKE ANY(ARRAY['one','mon','uuuu','wed','thu','fri','qwer']);
 name 
------
 mon
 qwer
 mon
(3 Zeilen)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda