create table t1 (a integer, b text, primary key (a));

create function f1 (integer) returns text as '
declare
  key		alias for $1;
  row		record;
begin
  for row in select a, b from t1 loop
	if row.a = key then
	  return row.b;
	end if;
  end loop;
  return null;
end;
' language plpgsql;

create function f2 (integer) returns text as '
declare
  key		alias for $1;
  result	record;
  tmp		record;
begin
  select 5 as a, f1 as b into result from f1(key);
  return result.b;
end;
' language plpgsql;

insert into t1 values (1, 'one');
insert into t1 values (2, 'two');

select f2(1);
alter table t1 add column c text;
select f2(2);
