Funciones con delete

Lists: pgsql-es-ayuda
From: Javier Rodriguez <jawibcn(at)hotmail(dot)com>
To: <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Funciones con delete
Date: 2007-11-08 14:35:12
Message-ID: BAY107-W13A93B5368EF4C7DD86793B58B0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

Haber si me podeis ayudar con esta funcion, tiene que borrar los lliuraments que lleven mas de un año, lo uq hago es un bucle y voy mirando cada lliurament si lleva mas de un año lo borro y paso al siguiente pero me da error
No se si esta mal el bucle o hago mal el delete

CREATE OR REPLACE FUNCTION ultim_anny()
RETURNS setof lliurament
LANGUAGE 'plpgsql' AS'
DECLARE
consulta lliurament%ROWTYPE;
BEGIN
for consulta in select * from lliurament where lliurament.data_entrega > current_date - integer ''365'' loop
delete consulta;
return next consulta;
end loop;
return;
END;';

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


From: Conxita Marín <cmarin(at)dims(dot)es>
To: "Javier Rodriguez" <jawibcn(at)hotmail(dot)com>, <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Funciones con delete
Date: 2007-11-08 15:20:29
Message-ID: 005c01c8221a$eb807ea0$10d8a8c0@pc13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

Hay que pensar en sql, no hay que hacer una función:

delete from lliurament where data_entrega::date - now() > 365;

Saludos.

Conxita Marín
Desarrollos Informáticos Modulares de Software, S.L.
www.dims.com

----- Original Message -----
From: Javier Rodriguez
To: pgsql-es-ayuda(at)postgresql(dot)org
Sent: Thursday, November 08, 2007 3:35 PM
Subject: [pgsql-es-ayuda] Funciones con delete

Haber si me podeis ayudar con esta funcion, tiene que borrar los lliuraments que lleven mas de un año, lo uq hago es un bucle y voy mirando cada lliurament si lleva mas de un año lo borro y paso al siguiente pero me da error
No se si esta mal el bucle o hago mal el delete

CREATE OR REPLACE FUNCTION ultim_anny()
RETURNS setof lliurament
LANGUAGE 'plpgsql' AS'
DECLARE
consulta lliurament%ROWTYPE;
BEGIN
for consulta in select * from lliurament where lliurament.data_entrega > current_date - integer ''365'' loop
delete consulta;
return next consulta;
end loop;
return;
END;';

------------------------------------------------------------------------------
Express yourself instantly with MSN Messenger! MSN Messenger


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Javier Rodriguez <jawibcn(at)hotmail(dot)com>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Funciones con delete
Date: 2007-11-08 18:26:15
Message-ID: 20071108182615.GP2938@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

Javier Rodriguez escribió:
> Haber si me podeis ayudar con esta funcion, tiene que borrar los lliuraments que lleven mas de un año, lo uq hago es un bucle y voy mirando cada lliurament si lleva mas de un año lo borro y paso al siguiente pero me da error
> No se si esta mal el bucle o hago mal el delete
>
> CREATE OR REPLACE FUNCTION ultim_anny()
> RETURNS setof lliurament
> LANGUAGE 'plpgsql' AS'
> DECLARE
> consulta lliurament%ROWTYPE;
> BEGIN
> for consulta in select * from lliurament where lliurament.data_entrega > current_date - integer ''365'' loop
> delete consulta;
> return next consulta;
> end loop;
> return;
> END;';

Esto no se hace asi, sino de la siguiente forma:

delete from lliurament where data_entrega - current_date > 365;

La verdad es que la funcion que nos muestras, no tiene ningun sentido.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support