Re: error ... con el comando EXECUTE

From: Rafael Martinez <r(dot)m(dot)guerrero(at)usit(dot)uio(dot)no>
To: gilberto(dot)castillo(at)etecsa(dot)cu
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: error ... con el comando EXECUTE
Date: 2009-05-20 18:49:07
Message-ID: 4A1450A3.6020903@usit.uio.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Gilberto Castillo Martínez wrote:
> Colegas:
>
> Intento hacer lo siguiente:
>
> CREATE OR REPLACE FUNCTION mira (nom_table character, pk_parent integer)
> RETURNS bigint AS
> $BODY$
> DECLARE
> cant bigint;
> BEGIN
> EXECUTE 'SELECT count(*) INTO cant FROM '|| quote_ident (nom_table)||'
> WHERE id='||pk_parent; ---||';';
> RETURN cant;
> END;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
>
>
> Hasta ahí todo bien.
>
> Cuando lanzo lo siguinte.
>
> select mira ('pais', 5);
>
>
> ERROR: EXECUTE of SELECT ... INTO is not implemented yet
> CONTEXTO: PL/pgSQL function "mira" line 4 at EXECUTE statement
>
> Según leí es un problemas de implementación de EXECUTE para versiones
> anteriores, Tengo instalado 8.3.7
>
> ¿Qué debo activar?
>

No necesitas activar nada y no necesitas utilizar EXECUTE para asignar
un valor a la variable cant.

Podrias intentar algo parecido a esto:

CREATE OR REPLACE FUNCTION mira (nom_table character, pk_parent integer)
RETURNS bigint AS
$BODY$
DECLARE
cant bigint;
BEGIN
SELECT INTO cant cnt FROM (SELECT count(*) AS cnt FROM quote_ident
(nom_table) WHERE id= pk_parent) value;
RETURN cant;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

Ya contaras
--
Rafael Martinez, <r(dot)m(dot)guerrero(at)usit(dot)uio(dot)no>
Center for Information Technology Services
University of Oslo, Norway

PGP Public Key: http://folk.uio.no/rafael/

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Luis A. Zevallos Cárdenas 2009-05-20 20:25:15 Problemas con un check
Previous Message Alvaro Herrera 2009-05-20 18:36:01 Re: consulta nuevamente para instalacion de postgres