Skip site navigation (1) Skip section navigation (2)

Re: FOR-IN-EXECUTE, why fail?

From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: "pgsql-general(at)postgresql(dot)org(dot)pgsql-novice(at)postgresql(dot)org(dot)pgsql-sql"(at)postgresql(dot)org
Subject: Re: FOR-IN-EXECUTE, why fail?
Date: 2004-07-17 09:49:08
Message-ID: cdasmt$lk4$2@floppy.pyrenet.fr (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novicepgsql-sql
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





In response to

pgsql-novice by date

Next:From: Steve TucknottDate: 2004-07-18 08:23:17
Subject: pgaccess - UNICODE problem
Previous:From: Jeff EckermannDate: 2004-07-16 22:45:16
Subject: Re: getting info out of a dump from postgresql

pgsql-general by date

Next:From: Peter EisentrautDate: 2004-07-17 10:03:17
Subject: Re: installation: cc and gcc how to?
Previous:From: gnariDate: 2004-07-17 09:45:37
Subject: Re: Three versions of Pg.pm on my machine

pgsql-sql by date

Next:From: Dario V. FassiDate: 2004-07-17 20:03:31
Subject: Migrate postgres databases from SQL_ASCII to UNICODE encoding
Previous:From: Rod TaylorDate: 2004-07-17 02:28:18
Subject: Re: Query plan discrepancies

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group