dbTalk Databases Forums  

FOR-IN-EXECUTE, why fail?

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss FOR-IN-EXECUTE, why fail? in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Marcos Medina
 
Posts: n/a

Default FOR-IN-EXECUTE, why fail? - 07-14-2004 , 10:13 AM






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?

Tahnks....

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: FOR-IN-EXECUTE, why fail? - 07-18-2004 , 11:23 PM






mmarencibia (AT) yahoo (DOT) es (Marcos Medina) writes:
Quote:
I wrote the following:
CREATE OR REPLACE FUNCTION escritorio.seq_valor_actual( text)
DECLARE
...
actual integer;
BEGIN
...
FOR actual IN EXECUTE v_query LOOP
The loop variable has to be a record or row variable, not an integer.

FWIW, 7.5 will give a better error message for this common mistake.
In CVS tip I get

ERROR: loop variable of loop over rows must be a record or row variable at or near "LOOP" at character 416
LINE 14: FOR actual IN EXECUTE v_query LOOP
^

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.