From: | Alejandro Carrillo <fasterzip(at)yahoo(dot)es> |
---|---|
To: | Leonel Fuentes Marrero <lfmarrero(at)uci(dot)cu> |
Cc: | "pgsql-es-ayuda(at)postgresql(dot)org" <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: Problema para construir una funcion dinamicamente |
Date: | 2012-02-08 13:53:56 |
Message-ID: | 1328709236.67938.YahooMailNeo@web27401.mail.ukl.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Creo que tienes que controlar el nodatafound en un bloque con una excepción.
>________________________________
> De: Leonel Fuentes Marrero <lfmarrero(at)uci(dot)cu>
>Para: pgsql-es-ayuda(at)postgresql(dot)org
>Enviado: Miércoles 8 de febrero de 2012 8:25
>Asunto: [pgsql-es-ayuda] Problema para construir una funcion dinamicamente
>
>Hola Familia:
>
>Quiero construir una funci贸n din谩micamente y me da error.
>
>--------------------------------------------------------
>ERROR: syntax error at or near "if"
>LINE 3: if not found then
> ^
>QUERY:
>SELECT * from pg_catalog.pg_class pgc,pg_catalog.pg_namespace pgn where pgc.relname = 'loca1' and pgc.relnamespace=pgn.oid and pgn.nspname='public';
>if not found then
> create table loca1 (id int);
>else
> insert into loca1 values (1);
> insert into loca1 values (2);
> insert into loca1 values (3);
>end if;
>
>CONTEXT: PL/pgSQL function "loca" line 18 at EXECUTE statement
>
>********** Error **********
>
>ERROR: syntax error at or near "if"
>Estado SQL:42601
>Contexto:PL/pgSQL function "loca" line 18 at EXECUTE statement
>--------------------------------------------------------
>
>la funci贸n es esta
>
>-------------------------------------------------------------
>CREATE OR REPLACE FUNCTION loca(_var text)
> RETURNS void AS
>$BODY$
>declare
>nuevas record;
>inicio record;
>nomb varchar;
>script text;
>begin
>script:= '
>SELECT * from pg_catalog.pg_class pgc,pg_catalog.pg_namespace pgn where pgc.relname = ' || '''loca1''' || ' and pgc.relnamespace=pgn.oid and pgn.nspname=' || '''' || $1::text || '''' || ';
>if not found then
> create table loca1 (id int);
>else
> insert into loca1 values (1);
> insert into loca1 values (2);
> insert into loca1 values (3);
>end if;
>';
>
> execute script;
> end;
>$BODY$
> LANGUAGE plpgsql VOLATILE
> COST 100;
>ALTER FUNCTION loca(text) OWNER TO postgres;
>-----------------------------------------------------------
>
>lo que me llama la atenci贸n es que agarro el c贸digo de la query y lo pongo en otra funci贸n y funciona bien.
>
>
>Gracias de antemano.
>
>Saludos
>
>Ing. Leonel Fuentes Marrero
>
>
>Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
>http://www.antiterroristas.cu
>http://justiciaparaloscinco.wordpress.com
>-
>Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org)
>Para cambiar tu suscripci髇:
>http://www.postgresql.org/mailpref/pgsql-es-ayuda
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Martin Li Causi | 2012-02-08 13:59:33 | Re: ayuda con oracle_fdw |
Previous Message | Leonel Fuentes Marrero | 2012-02-08 13:25:33 | Problema para construir una funcion dinamicamente |