I’m working with session variables and I would want to create a view which does the following:
if (myVar=1)
select * from my_table where X
else
select * from my_table where Y
Where X and Y are different clauses.
Is it possible?
Can this be implemented with a regular select statement (or I need stored procedures)?
Try something like this:
Details on postgresql session variables here.
UPD It will give the results of one of the
SELECT. Ifcurrent_setting(setting_name)equals to'setting A'the first query will return the results, but the second wont.For your example the query will look like:
UPD Checked: postgres executes only one of the queries.
EXPLAIN ANALYZEshows that the second query was planned but marked as(never executes).