From: | Michael Davis <michael(dot)davis(at)prevuenet(dot)com> |
---|---|
To: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Nulls |
Date: | 1999-03-09 19:53:48 |
Message-ID: | 93C04F1F5173D211A27900105AA8FCFC14525C@lambic.prevuenet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I have a function:
void *nz(void *bp) {
text *new_text;
new_text = (text *) palloc(sizeof(text)+2);
memset((void *) new_text, 0, sizeof(text)+2);
strcpy(VARDATA(new_text), ":");
VARSIZE(new_text) = sizeof(text)+2;
return (void *)(new_text);
}
I define the function in psql:
CREATE FUNCTION nz(text) RETURNS text AS
'/usr/src/pgsql/contrib/spi/psql_ext.so' LANGUAGE 'c';
I call the function:
select addressid, nz(state) from addresses where addressid = 3870;
If state is NULL, nz(state) still returns NULL! How can I get my nz()
function to reflect something other than NULL? The purpose behind this is
to have a concatenated string return a value even if any value is null. For
example:
select addressid, nz(state) || nz(country) from addresses where addressid =
3870;
Returns NULL if state is null or if country is null. I want it to return
the country if state is null.
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 1999-03-09 23:04:27 | Re: map |
Previous Message | D'Arcy J.M. Cain | 1999-03-09 19:00:59 | Re: [HACKERS] Niladic functions |