EXECUTE INTO on 8.2

Started by Jon Asherover 19 years ago2 messagesgeneral
Jump to latest
#1Jon Asher
jon.asher@gmail.com

I'm seeing some strange behavior with the following code. It compiles and
runs but returns an error on the Execute statement:
List index out of bounds(0)

DECLARE
srec record;
v_formula varchar;
v_result varchar;

BEGIN
v_formula = 'select 4 as val';
EXECUTE v_formula INTO srec;
END;

However, the old school version runs w/no problem:

BEGIN
v_formula = 'select 4 as val';

FOR srec IN EXECUTE v_formula LOOP
v_result = srec.val;
END LOOP;
END;

Any idea why the new syntax isn't working? (I'm running 8.2 on a Windows
dev box.)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jon Asher (#1)
Re: EXECUTE INTO on 8.2

"Jon Asher" <jon.asher@gmail.com> writes:

I'm seeing some strange behavior with the following code. It compiles and
runs but returns an error on the Execute statement:
List index out of bounds(0)

Worksforme. Want to provide a complete example instead of a fragmentary
one?

regression$# create or replace function foo() returns int as $$
declare srec record;
v_formula varchar;
v_result varchar;
BEGIN
v_formula = 'select 4 as val';
EXECUTE v_formula INTO srec;
return srec.val;
end $$ language plpgsql;
CREATE FUNCTION
regression=# select foo();
foo
-----
4
(1 row)

regression=#

regards, tom lane