Re: concatenar boolean con text, no puedo

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: "Miguel Beltran R(dot)" <yourpadre(at)gmail(dot)com>
Cc: Ayuda Postgres <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: concatenar boolean con text, no puedo
Date: 2007-12-03 22:14:06
Message-ID: 20071203221405.GB27306@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Miguel Beltran R. escribió:
> Hola lista
>
> Quiero hacer una función que se dispare cuando inserto un dato, esta
> función lo que debe hacer en insertar varios registros en otra tabla
> reflejando los datos insertados en la primera. La función es la
> siguiente :
>
> DECLARE
> sql TEXT;
> BEGIN
> FOR i IN NEW.inicial..NEW.final LOOP
> sql:='INSERT INTO holograma_entrega ';
> sql:=sql || '(foraneo, taller, fecha, tipo, holograma, holograma_orden';
> sql:=sql || 'VALUES (' || NEW.foraneo || ', ' || NEW.taller || ', ';
> sql:=sql || quote_literal(NEW.fecha) || ', ' ||
> quote_literal(NEW.tipo) || ', ';
> sql:=sql || i || ', ' || NEW.orden || ')'; --aqui uso i para poner el número
> RAISE NOTICE '%',sql;
> --EXECUTE sql;
> END LOOP;
> END

Prueba algo asi mejor:

insert into holograma_entrega
(foraneo, taller, fecha, tipo, holograma, holograma_orden)
select new.foraneo, new.taller, new.fecha, quote_literal(new,tipo), serie, new.orden
from generate_series(new.inicial, new.final) as serie;

Y te ahorras todo el loop, la concatenacion, etc.

--
Alvaro Herrera Developer, http://www.PostgreSQL.org/
"Always assume the user will do much worse than the stupidest thing
you can imagine." (Julien PUYDT)

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Regina Gonzalez 2007-12-03 22:39:03 xpath sobre postgres
Previous Message Nicolás Domínguez Florit 2007-12-03 21:27:34 Re: Ayuda con una consulta...