Search Postgresql Archives

dynamic parameters in procedure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux