Thread: silly NULL question
Howdy, I'm sure most of you PostgreSQL users out there will be able to answer this, but I'm just not finding the answer. Let's say I have a table called project that has three fields: field | type ------------------- id int name varchar(30) parent_id int right now there is only one row in the table: id | name | parent_id ----------------------------------- 1 | silly | You'll notice there is nothing in the parent_id as there is no parent for this particular project. Previously (with PostgreSQL 7.1) a query of: select * from project where name = 'silly' AND parent_id = NULL; Would return the row. Now with an upgrade to PostgreSQL 7.3 (yes, I know there are many changes and we're working through them right now) the same query returns nothing. Dropping the "AND parent_id = NULL" returns the row as expected. Now, what is the correct specifier for an empty int value? Or, are there suggestions for how to create that column (like using NULL as the default maybe) that experts can clue-stick me with? Thanks for your time. If this is the wrong list to ask these questions to please point me in the right direction. -dan
> Would return the row. Now with an upgrade to PostgreSQL 7.3 (yes, I know > there are many changes and we're working through them right now) the same > query returns nothing. Dropping the "AND parent_id = NULL" returns the row > as expected. NULL is similar to UNKNOWN. So, NULL = NULL is the similar to UNKNOWN = UNKNOWN. Since you don't know it, how can you tell if they're equal or not? Syntax you're looking for is: AND parent_id IS NULL If you really really really need = NULL (due to some MS product which ignores SQL standards -- say MS Access) there is a toggle in the postgresql.conf file to allow automated conversion of = NULL to IS NULL within the server.
>>>>> "RT" == "Rod Taylor" <rbt@rbt.ca>: RT> NULL is similar to UNKNOWN. RT> RT> So, NULL = NULL is the similar to UNKNOWN = UNKNOWN. Since you don't RT> know it, how can you tell if they're equal or not? RT> RT> Syntax you're looking for is: AND parent_id IS NULL ah, of course. Thanks Rod. RT> If you really really really need = NULL (due to some MS product which RT> ignores SQL standards -- say MS Access) there is a toggle in the RT> postgresql.conf file to allow automated conversion of = NULL to IS NULL RT> within the server. ah ha! the culprit. I see this was default through 7.1. Thanks again for accurate and quick reply. -dan