Re: Nulls get converted to 0 problem
От | DeJuan Jackson |
---|---|
Тема | Re: Nulls get converted to 0 problem |
Дата | |
Msg-id | 3EE119B3.6070208@speedfc.com обсуждение исходный текст |
Ответ на | Re: Nulls get converted to 0 problem (Jon Earle <je_pgsql@kronos.honk.org>) |
Список | pgsql-general |
Jon Earle wrote: >But that doesn't answer the question that, what is the difference between >no data and null? They both indicate zero value. There's some esoteric >difference that I'm missing, probably because my programming background >has not involved database work until very recently. > >Cheers! >Jon > > > I believe the point that was being made is that if you treat NULL the same as "" then even in C /C++, you get at best unpredictable behavior. I think what you are missing is that in C/C++ NULL == 0 (I have yet to see a C/C++ implementation where this is not true) from a pointer perspective. So, the pointer can be tested for trueness in and of itself, which just happens to be the same case for the C/C++ end of string character '\0' == 0. The thing to remember when programming C/C++ is that a NULL pointer is not equal to "", they represent two completely different states for the variable in question. The same situation is true in a database context NULL stands for unknown value (NOTE: This is not what it means in C/C++), an empty string is a known value so is 0. It's like in Monty Python's Holy Grain, when they come to the come to the bridge the bridge keeper had a database of each ones name and quest but he had a NULL value for whether or not the swallow was African or European. Another possible image for a database NULL, would be the state of Shrodinger's cat before you look in the box (completely unknown). After looking in the box (know the values for the cats state) the only valid states are ALIVE and DEAD, but before you look the only possible condition is unknown (NULL), but you still need other information in the tuple/row about the cat (such as it's favorite chew toy, if it's house broken, if it's had it's shots, is it male or female, has it been spade or neutered, ...), which are known before you look into the box.
В списке pgsql-general по дате отправления: