From: Philippe Lang <philippe.lang@attiksystem.ch>
To: pgsql-sql@postgresql.org
Subject: Re: quote_nullable alternative?
Date: Fri, 9 Nov 2007 08:14:30 +0100
Message-ID: <6C0CF58A187DA5479245E0830AF84F42337E3C@poweredge.attiksystem.ch> (raw)
References: <6C0CF58A187DA5479245E0830AF84F4218CF6B@poweredge.attiksystem.ch>
pgsql-sql-owner@postgresql.org wrote:
> Hi,
>
> There has been a recent discussion on the hacker mailing-list
> recently, regarding a new patch for postgresql, that returns 'NULL'
> instead of NULL when a NULL value is passed as a parameter.
>
> It's exactly what I need on my 8.2.5 server.
>
> Is there an alternative to patching the server in order to get that
> kind of feature, for example with plpgsql code?
>
> Because of that bug:
>
> http://www.postgresql.org/docs/faqs.FAQ.html#item4.19
>
> ... I'm obliged to call EXECUTE at every temporary table call, and
> constructing the query string where parameters can be NULL is really
> a nightmare...
>
> Thanks
Hi,
It might not be the most elegant solution, but I ended up writing these
functions to solve my problem:
CREATE OR REPLACE FUNCTION nullable_param(param text)
RETURNS text AS
$$
BEGIN
IF param IS NULL THEN
RETURN 'NULL';
ELSE
RETURN '''' || param || '''';
END IF;
END
$$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION nullable_param(param varchar)
RETURNS varchar AS
$$
BEGIN
IF param IS NULL THEN
RETURN 'NULL';
ELSE
RETURN '''' || param || '''';
END IF;
END
$$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION nullable_param(param decimal)
RETURNS varchar AS
$$
BEGIN
IF param IS NULL THEN
RETURN 'NULL';
ELSE
RETURN CAST(param AS varchar);
END IF;
END
$$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION nullable_param(param int)
RETURNS varchar AS
$$
BEGIN
IF param IS NULL THEN
RETURN 'NULL';
ELSE
RETURN CAST(param AS varchar);
END IF;
END
$$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION nullable_param(param date)
RETURNS varchar AS
$$
BEGIN
IF param IS NULL THEN
RETURN 'NULL';
ELSE
RETURN '''' || param || '''';
END IF;
END
$$
LANGUAGE 'plpgsql' VOLATILE;
Regards,
Philippe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: philippe.lang@attiksystem.ch
Subject: Re: quote_nullable alternative?
In-Reply-To: <6C0CF58A187DA5479245E0830AF84F42337E3C@poweredge.attiksystem.ch>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox