I need to implement a conditional
SELECT statement based on the result of another statement. I don't want to create a function for this purpose, but simply using conditional
My unsuccessful approach looks as below:
DO $do$ BEGIN IF SELECT count(*) FROM table1 < 1 THEN SELECT * FROM table2; RETURN QUERY; ELSE SELECT * FROM table3; RETURN QUERY; END IF; END $do$
I could accomplish the same result by checking the results of my query in PHP and based on this, perform another query, yet I'm wondering if it's possible to do this solely in PostgreSQL.