Hi,
I want to create a stored procedure that can take a dynamic number of
in-parameters and base an inside-query based on those parameters.
My ideas was to use text[] as input parameters like this.
CREATE OR REPLACE FUNCTION get_table(text[])
RETURNS SETOF table AS
'
DECLARE
params ALIAS FOR $1;
query VARCHAR;
entry RECORD;
BEGIN
query := \'SELECT * FROM table\';
FOR entry IN EXECUTE query LOOP
RETURN NEXT entry;
END LOOP;
RETURN;
END;
'
LANGUAGE 'plpgsql';
My question is how do I loop the input-parameters?
I plan to call it like this:
SELECT * FROM get_table('{"field1=1", "field2=3"}');
Do I make any sense? :)
regards
Robin