knowledge-database (beta)

Current group: pgsql.interfaces.

How to detect NULL in VarChar (C function)

How to detect NULL in VarChar (C function)  
Benno_Pütz
 Re: How to detect NULL in VarChar (C function)  
Tom Lane
 Re: How to detect NULL in VarChar (C function)  
Michael Fuhr
From:Benno_Pütz
Subject:How to detect NULL in VarChar (C function)
Date:Thu, 13 Jan 2005 17:53:40 +0100
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.

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.

Any help will be appreciated

Benno


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
From:Tom Lane
Subject:Re: How to detect NULL in VarChar (C function)
Date:Thu, 13 Jan 2005 14:49:56 -0500
=?ISO-8859-1?Q?Benno_P=FCtz?= writes:
> 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.

Use PG_ARGISNULL(). See
33.7.4. Calling Conventions Version 1 for C-Language Functions
at
http://www.postgresql.org/docs/7.4/static/xfunc-c.html

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings
From:Michael Fuhr
Subject:Re: How to detect NULL in VarChar (C function)
Date:Thu, 13 Jan 2005 12:50:31 -0700
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
STRICT.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
   

Copyright © 2006 knowledge-database   -   All rights reserved