Passing nulls into PL/pgSQL functions

From: Adam Witney <awitney(at)sghms(dot)ac(dot)uk>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Passing nulls into PL/pgSQL functions
Date: 2003-04-16 20:09:53
Message-ID: BAC37721.16F9B%a.witney@sghms.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi,

Is it possible to pass a null value into a PL/pgSQL function. For example

CREATE TABLE mytable(id int, name text);

CREATE OR REPLACE FUNCTION myfunc(int, text) returns int AS '
DECLARE
_id ALIAS FOR $1;
_name ALIAS FOR $2;

BEGIN
EXECUTE ''INSERT INTO mytable (id, name) VALUES(''||_id||'',
''''''||_name||'''''')'';

RETURN _id;
END

' LANGUAGE 'plpgsql';

Now, this works ok

select myfunc(1, 'foo');

However, this fails

select myfunc(1, null);

Is there a way of doing it such that I can pass a null sometimes?

Thanks for any help

Adam

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-04-16 20:31:31 Re: Passing nulls into PL/pgSQL functions
Previous Message Bruce Momjian 2003-04-16 18:39:05 Re: will an honest French ISP please stand up