Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!