Can you have an SQL block that accepts a variable for input, uses that variable in a join and returns a result set.
The kicker is that I have been asked to do this outside a function - i.e. within an SQL block.
So, for example, I want to pass the value 1234567890 to the variable v_hold:
DO $$
declare
v_hold integer;
BEGIN
select * from t_table_A where ID = v_hold ;
--return alert_mesg;
END$$;
--$$ LANGUAGE plpgsql
The testing I've done says that in order to return a result set, you have to define that in a RETURN TABLE declaration. I've tried to define this outside a function, but I haven't figured it out.
Can this be done outside a function - i.e pass a variable and return a result set based on a select statement which references a variable in the where clause?
DOcommand is not an "SQL block", even though its default language PL/pgSQL has "blocks" - which wouldn't be called "SQL blocks". AndRETURNS TABLE(withS) is only available in aFUNCTION. The prepared statement suggested by @aengus may be the compromise. Be aware that it lives and dies with the session (unless deallocated earlier) - unlike a function, which is a persisted object.