I'm trying to write a function that takes a text input and returns
a text output. I can get this to work. The problem is that I want
to return NULL when the input string doesn't match the criteria I
desire. Unfortunately, returning NULL seems to crash the backend.
i.e. if I did

#include "postgres.h"
text * andytest ( text * str )
return NULL;

The backend would quit unexpectantly when I ran
select andytest('fds');
or select andytest(NULL);

Obviously, there must be some way to create a NULL text * return
variable, but I haven't been able to find it. I've looked at all
the code I've been able to find to no avail.


Search Discussions

  • Tom Lane at Aug 12, 2000 at 12:17 am

    Andrew Selle writes:
    Obviously, there must be some way to create a NULL text * return
    You would think that, but you'd be wrong :-( --- at least for current
    releases; this problem has been fixed for 7.1 by creating a new API
    for user-defined functions.

    With the old API, for the case of single-argument functions, you can
    fake it via an ugly kluge: declare a second argument "bool *isNull"
    (at the C level only, not in the SQL definition) and set *isNull to
    TRUE if you want to return a NULL. This does not work if the function
    doesn't have exactly one SQL argument, however.

    regards, tom lane

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-hackers @
postedAug 11, '00 at 8:29p
activeAug 12, '00 at 12:17a

2 users in discussion

Andrew Selle: 1 post Tom Lane: 1 post



site design / logo © 2021 Grokbase