While playing around with pl/pgsql... i stumbled on something i have no real explanation for.

This is what i did:

Create the following function:
CREATE OR REPLACE FUNCTION public.test(int4, int4)
RETURNS int4 AS
'
DECLARE
integert integer;
rec RECORD;
col_id integer;
integerr integer;

BEGIN
integert := $1;
integerr := $2;
if integert = 2 THEN

SELECT INTO rec id FROM testing WHERE col2 = integert;
col_id := rec.id;
ELSE
return 8;
END IF;

RETURN 5;
END;

'
LANGUAGE 'plpgsql' VOLATILE;

Created the following table:

Create table testing
(
id int,
col2 int,
col3 int
)

and inserted:
insert into id values (1,2,3)

Finaly i tested the function using:

select test(2,null)
And as expected, the result was 1.

Now i figured, that if would do "select test(2)" the function would use "2" as $1 and give 1 as a result back.
But it didnt, it returned a null value.

Is that because the function is expecting 2 integer values and returns null when it only sees 1 integer value?

-Ed