From: Edward Date: Tue, 14 Jan 2014 05:44:49 +0000 (+0800) Subject: pgsql/core_enum_seqmax_update.sql X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=commitdiff_plain;h=aa4c860a2ef7550fe32e831c13b7375931c80967 pgsql/core_enum_seqmax_update.sql --- diff --git a/pgsql/core_enum_seqmax_update.sql b/pgsql/core_enum_seqmax_update.sql index e69de29b..90f46317 100644 --- a/pgsql/core_enum_seqmax_update.sql +++ b/pgsql/core_enum_seqmax_update.sql @@ -0,0 +1,24 @@ + +DROP FUNCTION IF EXISTS core_enum_seqmax_update; + +CREATE OR REPLACE FUNCTION core_enum_seqmax_update(in_etype varchar(128)) + RETURNS INTEGER AS +$BODY$ + +DECLARE + v_seqmax INTEGER; + +BEGIN + + SELECT MAX(seqid) +1 INTO v_seqmax FROM core_enum WHERE + etype = in_etype; + UPDATE core_enum SET seqmax = v_seqmax WHERE etype = in_etype; + RETURN v_seqmax; + +END; +$BODY$ + LANGUAGE plpgsql VOLATILE + COST 100; + +ALTER FUNCTION core_enum_seqmax_update(varchar) + OWNER TO admin; \ No newline at end of file