Skip site navigation (1) Skip section navigation (2)

NULL handling question

From: "Vazsonyi Peter[ke]" <neko(at)kornel(dot)szif(dot)hu>
To: hackers(at)postgreSQL(dot)org
Subject: NULL handling question
Date: 1999-03-26 19:37:48
Message-ID: Pine.A32.4.05.9903261956220.3136-100000@kornel.szif.hu (view raw or flat)
Thread:
Lists: pgsql-hackers
Hello!

I tried to create a simple function, to "variable value validate" :)
Here:
text *default_text(text* input) {
	char *ret;
	char def[20];
	if (input) ret=input;
	strcpy((def+4),"Default");
	(*((int4*)def)) = strlen(def+4)+4;
	ret=def;
	elog(NOTICE,"Here:%i", (int4)(*def))
}
This retunrs with the text "Default", if input value IS NULL, and the
with original value if not.
So try it with postgres:
tron=> create table test (v text);
tron=> insert into test values(NULL);
tron=> insert into test values('1');
CREATE INSERT INSERT
tron=> select default_text(v) from test;
NOTICE:  Here: 11
NOTICE:  Here: 5
?column?
--------

       1
I don't seek this in the source, but i think, all function, who take a NULL
value as parameter can't return with a NOT NULL value.
But why? Ooops... And can i check about an int4 if IS NULL ?
??
--
 //  NeKo(at)KorNeL(dot)szif(dot)hu // http://lsc.kva.hu/  //


In response to

Responses

pgsql-hackers by date

Next:From: The Hermit HackerDate: 1999-03-26 19:48:36
Subject: Re: [HACKERS] PostgreSQL LOGO (was: Developers Globe (FINAL))
Previous:From: Thomas LockhartDate: 1999-03-26 19:36:50
Subject: Re: [HACKERS] Going on vacation

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group