Aqui esta :::
CREATE OR REPLACE FUNCTION "public"."get_secuencia" (varchar, concat boolean) 
RETURNS varchar AS$body$DECLARE       tipodoc ALIAS FOR $1;       secuencia 
int4;       registro record;BEGIN
   
/*-----------------------------------------------------------------------------------------*/
    secuencia :=1;    select into registro * from t_secuencias   where 
f_tipo_documento = tipodoc for update;
   IF NOT FOUND  THEN       INSERT INTO t_secuencias (f_tipo_documento, 
f_secuencia)  VALUES (tipodoc,secuencia);    ELSE       secuencia:= 
registro.f_secuencia+secuencia;        UPDATE t_secuencias SET f_secuencia = 
secuencia   WHERE f_tipo_documento = tipodoc;    END IF;
if concat then    return tipodoc||trim(both ' ' from 
(to_char(secuencia,'0000000')));else  return trim(both ' ' from 
(to_char(secuencia,'0000000')));   end if;  END;$body$LANGUAGE 'plpgsql' 
VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
*-------------------------------------------------------* 
*-Edwin Quijada 
*-Developer DataBase 
*-JQ Microsistemas 

*-Soporte PostgreSQL

*-www.jqmicrosistemas.com
*-809-849-8087
*-------------------------------------------------------*



> CC: i...@pgsistemasmdq.com.ar; pgsql-es-ayuda@postgresql.org
> Subject: RE: [pgsql-es-ayuda] Actualizar fila y controlar concurrencia
> From: alvhe...@alvh.no-ip.org
> To: listas_quij...@hotmail.com
> Date: Mon, 22 Aug 2011 13:43:52 -0300
> 
> Excerpts from Edwin Quijada's message of sáb ago 20 10:47:52 -0400 2011:
> > 
> > Alvaro, esta semana me paso algo interesante con eso. Tengo una funcion que 
> > hace exactamente eso bloque el record , luego el update, bien hasta ahi, lo 
> > raro es que puse dicha funcion dentro de un trigger para generar dicha 
> > secuencia pero al hacer un insert todo se queda bloqueado y el inserrt 
> > nunca prospera pero si dentro del insert invoco a la funcion no hay 
> > problema solo al ponerla dentro del trigger.Algo extrano, nunca me habia 
> > dado cuenta porque siempre la uso , la funcion, desde la aplicacion.
> 
> ¿Qué hace la función?
> 
> -- 
> Álvaro Herrera <alvhe...@alvh.no-ip.org>
> -
> Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda@postgresql.org)
> Para cambiar tu suscripci�n:
> http://www.postgresql.org/mailpref/pgsql-es-ayuda
                                          

Responder a