From: Gaetano Mendola <mendola@bigfoot.com>
To: " <pgsql-general@postgresql.org.pgsql-novice>
Subject: Re: FOR-IN-EXECUTE, why fail?
Date: Sat, 17 Jul 2004 11:49:08 +0200
Message-ID: <cdasmt$lk4$2@floppy.pyrenet.fr> (raw)
In-Reply-To: <e0e689c2.0407140713.3e898cc8@posting.google.com>
References: <e0e689c2.0407140713.3e898cc8@posting.google.com>
Marcos Medina wrote:
> I wrote the following:
> CREATE OR REPLACE FUNCTION escritorio.seq_valor_actual( text)
> RETURNS integer AS '
> DECLARE
> secuencia ALIAS FOR $1;
> valor_actual integer := 0;
> v_query text;
> actual integer;
> BEGIN
> RAISE NOTICE ''el parametro tiene el siguiente valor %'' ,secuencia;
>
> v_query := ''SELECT last_value FROM '' || quote_ident(secuencia);
> RAISE NOTICE ''la sentencia a ejecutar es %'' ,v_query;
>
> FOR actual IN EXECUTE v_query LOOP
> valor_actual := actual;
> END LOOP;
>
> RETURN valor_actual;
>
> END;
> 'LANGUAGE 'plpgsql';
>
> And i call:
> select seq_valor_actual('s_id_reserva');
>
>
> The s_id_reserva is a sequence. The error is the following:
> WARNING: plpgsql: ERROR during compile of seq_valor_actual near line 12
> ERROR: missing .. at end of SQL expression
>
> I think the problem is in the FOR but i see correct all.
>
> Can i help me?
>
> Any idea?
You shall declare actual as RECORD and perform inside the loop:
valor_actual = actual.last_value;
Regards
Gaetano Mendola
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mendola@bigfoot.com, pgsql-general@postgresql.org.pgsql-novice
Subject: Re: FOR-IN-EXECUTE, why fail?
In-Reply-To: <cdasmt$lk4$2@floppy.pyrenet.fr>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox