Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

dynamic parameters in procedure



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




Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group