Subject: functions with text type arguments

From: Bart Maessen <[email-masked]>
Date: Thu, 29 Jul 93 12:26:32 MET DST

Dear Sirs,
 
The returned value of functions which has as an variable
length argument type is not correct in the case that the variable
length argument is (null).
E.G.
 
Suppose we have the following function (c-code):
    #include <stdio.h>
    #include <string.h>
    #include "utils/log.h"
    #include "utils/geo-decls.h"
    #include "tmp/postgres.h"
 
    int bart_test(str)
    text *str;
    {
      int result;
 
      result = 1;
      return result;
    };
 
As you can see this functions always returns 1 regardless what
the value of the parameter is.
 
define the function in the database:
  define function bart_test(language="c",
  returntype=int4)
  arg is (text)
  as "<properpath>/bart_test.o"
 
create a table
  create t(a=int4,b=text)
 
append two tuples:
  append t(a=1)
  append t(a=2,b="something")

retrieving the table shows (retrieve (t.all))
    -----------------------------
    | a           | b           |
    -----------------------------
    | 1           | (null)      |
    -----------------------------
    | 2           | something   |
    -----------------------------
 
the value in the b-column is in one case null and the other case
it contains text info.
 
Now perform the following:
  retrieve (a=bart_test(t.b))
 
The result is:
  ---------------
  | a           |
  ---------------
  | (null)      |
  ---------------
  | 1           |
  ---------------

So apparently the value of the text argument does matter, despite
what the c-code does.

Bart Maessen
Physics and Electronics Laboratory TNO
The Netherlands
e-mail: [email-masked]

---

From: [email-masked] (Paul M. Aoki)
Date: Thu, 29 Jul 93 07:25:59 -0700

> length argument is (null).

the argument is not the NULL pointer.  the argument actually does
not exist -- it's a null value (in the database sense).  hence the
function is not run on the argument at all (since the null value
has no meaning to C functions -- there's no one value you can pass
to ALL possible functions and have them understand that it's null).

when i run this with, say, int4 arguments and int4inc, the same 
thing happens (which is what you would expect) -- the retrieved result 
is null.

i'm looking at the join thingy now.
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki