dynamic parameters in procedure - Mailing list pgsql-general

From Robin Ericsson
Subject dynamic parameters in procedure
Date
Msg-id 1085141531.20206.84.camel@pylver.localhost.nu
Whole thread Raw
List 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


pgsql-general by date:

Previous
From: Jan Wieck
Date:
Subject: Re: Equivalent for mysql's FOUND_ROWS()
Next
From: Christopher Browne
Date:
Subject: Re: About PostgreSQL