RE: update ... current of - Solucion

From: "Juan Carlos Barranco de Paz" <jcb(at)greccosoft(dot)es>
To: <pgsql-es-ayuda(at)postgresql(dot)org>, "'Alvaro Herrera'" <alvherre(at)commandprompt(dot)com>
Subject: RE: update ... current of - Solucion
Date: 2008-06-18 16:46:14
Message-ID: 001f01c8d162$d344a2b0$79cde810$@es
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

>-----Mensaje original-----
>De: pgsql-es-ayuda-owner(at)postgresql(dot)org
[mailto:pgsql-es-ayuda-owner(at)postgresql(dot)org] En nombre de Juan Carlos
Barranco de Paz
>Enviado el: martes, 17 de junio de 2008 19:57
>Para: pgsql-es-ayuda(at)postgresql(dot)org
>Asunto: [pgsql-es-ayuda] update ... current of

>Hola , he instalado la 8.3, estoy intentando hacer un update a través de un
>cursor, nueva característica que incorpora esta versión.

>Ya he conseguido que no me de error a la hora de cargar, pero si me da a la
>hora de ejecutar.

>Este es el error

>ERROR: el cursor «<unnamed portal 1>» no es un recorrido simplemente
>actualizable de la tabla «dw21vent»
>Estado SQL:24000
>Contexto:sentencia SQL: «update dw21vent set beneficio_ult = 1 where
current
>of $1 »
>PL/pgSQL function "dw0_0012_1" line 97 at SQL statement
>sentencia SQL: «SELECT dw0_0012_1( $1 )»
>PL/pgSQL function "dw0_0012" line 22 at PERFORM

>Esta es la function n si

>CREATE OR REPLACE FUNCTION dw0_0012_1(dw01 dw01conf)
> RETURNS smallint AS
>$BODY$
>DECLARE

>dw0_0012_1_c refcursor;
>dw21 dw21vent%ROWTYPE;
>BEGIN
> OPEN dw0_0012_1_c FOR SELECT
> *
> from dw21vent
> where empresa = dw01.empresa
> order by 1,2,3

;
>
> LOOP
> FETCH dw0_0012_1_c INTO dw21;
> EXIT WHEN NOT FOUND;
>
> update dw21vent set beneficio_ult = beneficio_ult + 1
> where current of dw0_0012_1_c;
>
> END LOOP;

> CLOSE dw0_0012_1_c;

> RETURN 1;
>END;
>$BODY$
> LANGUAGE 'plpgsql' VOLATILE

Hay que añadir for update
....
order by 1,2,3 for update
funciona tanto con OPEN cursor FOR SELECT o FOR EXECUTE

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Roberto Rodríguez Pino 2008-06-18 16:50:34 Re: declarando una variable en funcion
Previous Message Terry Yapt 2008-06-18 16:22:15 A vueltas con los ENCODING's/LOCALES/etc... :-(