2

Following is my sample function

create or replace function samp(in a int) returns int as
$$
declare 
val int;
val1 int;
begin
select coalesce(a-1,1) into val,coalesce(a-2,1) into val1;
return val + val1;
end;
$$
language plpgsql 

when executing it I get following error

ERROR: "coalesce" is not a known variable LINE 7: select coalesce(a-1,1) into val,coalesce(a-2,1) into val1;

bigbiff
  • 75
  • 1
  • 1
  • 8

1 Answers1

5

Your syntax is wrong - into is a single clause that applies to all the variables, not a keyword that should be applied to each variable:

SELECT coalesce(a-1,1), coalesce(a-2,1)
INTO   val, val1;
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 1
    Huh. I never knew you could specify `into` multiple times, and have always used anonymous records. Nice. – Craig Ringer Oct 02 '15 at 08:29
  • 2
    @CraigRinger I am pretty sure you can't. It should be a single `INTO` clause. You can indeed have multiple targets, one for each select list item. – Patrick Oct 02 '15 at 09:24