- CREATEorReplaceFUNCTIONfunc_getnextid(
- tablenamevarchar(240),
- idnamevarchar(20)default'id')
- RETURNSintegerAS$funcbody$
- Declare
- sqlstringvarchar(240);
- currentIdinteger;
- Begin
- sqlstring:='selectmax("'||idname||'")from"'||tablename||'";';
- EXECUTEsqlstringintocurrentId;
- ifcurrentIdisNULLorcurrentId=0then
- return1;
- else
- returncurrentId+1;
- endif;
- End;
- $funcbody$LANGUAGEplpgsql;
-
CREATE OR REPLACE FUNCTION test_get_sql(IN sql character varying,OUT io_cursor_ref refcursor)
RETURNS record AS
$BODY$
DECLARE
BEGIN
OPEN IO_CURSOR_REF FOR
execute sql;RETURN; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; ALTER FUNCTION test_get_sql(character varying)