pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to detect NULL in VarChar (C function)
3+ messages / 3 participants
[nested] [flat]
* How to detect NULL in VarChar (C function)
@ 2005-01-13 16:53 Benno Pütz <puetz@mpipsykl.mpg.de>
2005-01-13 19:49 ` Re: How to detect NULL in VarChar (C function) Tom Lane <tgl@sss.pgh.pa.us>
2005-01-13 19:50 ` Re: How to detect NULL in VarChar (C function) Michael Fuhr <mike@fuhr.org>
0 siblings, 2 replies; 3+ messages in thread
From: Benno Pütz @ 2005-01-13 16:53 UTC (permalink / raw)
To: pgsql-interfaces
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to detect NULL in VarChar (C function)
2005-01-13 16:53 How to detect NULL in VarChar (C function) Benno Pütz <puetz@mpipsykl.mpg.de>
@ 2005-01-13 19:49 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2005-01-13 19:49 UTC (permalink / raw)
To: puetz@mpipsykl.mpg.de; +Cc: pgsql-interfaces
=?ISO-8859-1?Q?Benno_P=FCtz?= <puetz@mpipsykl.mpg.de> 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to detect NULL in VarChar (C function)
2005-01-13 16:53 How to detect NULL in VarChar (C function) Benno Pütz <puetz@mpipsykl.mpg.de>
@ 2005-01-13 19:50 ` Michael Fuhr <mike@fuhr.org>
1 sibling, 0 replies; 3+ messages in thread
From: Michael Fuhr @ 2005-01-13 19:50 UTC (permalink / raw)
To: Benno Pütz <puetz@mpipsykl.mpg.de>; +Cc: 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
STRICT.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-01-13 19:50 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-01-13 16:53 How to detect NULL in VarChar (C function) Benno Pütz <puetz@mpipsykl.mpg.de>
2005-01-13 19:49 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-01-13 19:50 ` Michael Fuhr <mike@fuhr.org>
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