Return select statement with sql case statement

From: hmidi slim <hmidi(dot)slim2(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Return select statement with sql case statement
Date: 2018-07-04 12:48:38
Message-ID: CAMsqVxuBE0iHU=-_LCS2PyonGFvJwgrs6LLrzuGU53m7VqYBQA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I need to use conditional expression in my query, So I want to make a query
like this:
select numberOfPremiumDays
case when numberOfPremiumDays = date_part('day',
('2018-11-05'::timestamp) - ('2018-11-01'::timestamp)) then
select product_id,
price
from product
where occupation_type_id = 1
group by product_id, occupation_type_id

However, in the documentation I found that the return of case was a value,
not like in my case I want to return a select statement.
How can I use a conditional expression in a sql query?
Best Regards.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom van Tilburg 2018-07-04 13:34:42 Postgres sometimes stalling on 'percentile_cont'
Previous Message Boblitz John 2018-07-04 11:08:33 Unable to Connect to DB Instance