dynamic parameters in procedure

From: Robin Ericsson <robin(dot)ericsson(at)profecta(dot)se>
To: pgsql-general(at)postgresql(dot)org
Subject: dynamic parameters in procedure
Date: 2004-05-21 12:12:11
Message-ID: 1085141531.20206.84.camel@pylver.localhost.nu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Browne 2004-05-21 12:23:26 Re: About PostgreSQL
Previous Message Jan Wieck 2004-05-21 12:05:06 Re: Equivalent for mysql's FOUND_ROWS()