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

248
Visualizações
Postgresql - execute only certain IF statements

I would like to put toghether the reslt of some queries by using UNION. But I want to execute only some of the queries... in the sample below the part ('Daily','Yearly') will be filled in automatically.

something along the lines of:

(if 'Daily' in ('Daily','Yearly') then
my first query goes here...
end if)
UNION ALL
(if 'Monthly' in ('Daily','Yearly') then
my second query goes here...
end if)
UNION ALL
(if 'Yearly' in ('Daily','Yearly') then
my third query goes here...
end if)

In this sample, the result of the second query should not be present in the output.

on a side note: I do already have the 3 working queries, what i am missing is how to execute them dynamically and put them toghether to a single output.

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

0

Try to put these conditions in the appropriate "Where" sections. Engine have to skip queries if the literal conditions are not met.

my first query goes here...
Where 'Daily' in ('Daily','Yearly')
UNION ALL
my second query goes here...
Where 'Monthly' in ('Daily','Yearly')
UNION ALL
my third query goes here...
Where 'Yearly' in ('Daily','Yearly')
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