Skip site navigation (1) Skip section navigation (2)

Re: How to detect NULL in VarChar (C function)

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Benno Pütz <puetz(at)mpipsykl(dot)mpg(dot)de>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: How to detect NULL in VarChar (C function)
Date: 2005-01-13 19:50:31
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
On Thu, Jan 13, 2005 at 05:53:40PM +0100, Benno Pütz wrote:

> I try to write a function that combines two varchar columns.
> Now the problem arose that (either) one of te columns may contain a NULL 
> value, in which case the return value seems to become NULL.

What do you mean "seems" to become NULL?  Is it NULL or not?  You
can check with IS NULL:

SELECT foo(value1, value2) IS NULL;

> I have not been able to find a description of how to detect NULL values 
> in VarChar variables passed to C-functions to catch those cases.

If you're using the version-1 calling conventions then you can use
PG_ARGISNULL(); this macro is mentioned in the "C-Language Functions"
section of the "Extending SQL" chapter in the documentation.

If you created the function as STRICT (aka RETURNS NULL ON NULL
INPUT) and any of the arguments are NULL, then the function won't
be called at all and the return value will be NULL.  If you want
to handle NULL values within the function then don't declare it

Michael Fuhr

In response to

pgsql-interfaces by date

Next:From: Satheesh ManiDate: 2005-01-14 22:20:09
Subject: PGXML
Previous:From: Tom LaneDate: 2005-01-13 19:49:56
Subject: Re: How to detect NULL in VarChar (C function)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group