I want to execute a dynamic SQL statement, with its returned value being the conditional for an IF statement:
IF EXECUTE \'EXISTS (SELECT 1 FROM
Matt,
From the syntax above, you're writing PL/pgSQL, not SQL. On tht assumption, there are two ways to do what you want, but both will require two lines of code:
EXECUTE 'SELECT EXISTS (SELECT 1 FROM ' || table_variable || ' );' INTO boolean_var;
IF boolean_var THEN ...
Or:
EXECUTE 'SELECT 1 FROM ' || table_variable || ' );';
IF FOUND THEN ...
"FOUND" is a special variable which checks if the last query run returned any rows.