Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following table in PostgreSQL:

   Column    |          Type          |                         Modifiers
-------------+------------------------+-----------------------------------------------------------
 description | text                   | not null
 sec_r       | integer[]              |

My two array of integers sec_r have some fields that have "null" values, but I guess it isn't null?

Whenever I try to select * from this table where sec_r = null I get 0 rows.

|  description     |  sec_r  |
+------------------+---------+
| foo bar foo bar  |         |
| foo bar foo bar  | {1,2,3} |
| foo bar foo bar  |         |
| foo bar foo bar  | {9,5,1} |
(4 rows)

Doing select * from TheTable where 1 = ANY (sec_r) returns the correct rows however.

How do I select the rows where the array is blank?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

You should use IS NULL and not = NULL in SQL.

Try:

SELECT * FROM the_table WHERE sec_r IS NULL
share|improve this answer
    
Genius. Hahaa, okay I'll accept this in the 11 minute timeout. –  Incognito Jun 3 '11 at 19:39
    
You can also enable transform_null_equals property, so sec_r = null will be treated as sec_r IS NULL or use ISNULL shorthand, but your best friend is SQL standard way IS NULL. –  Grzegorz Szpetkowski Jun 3 '11 at 20:15

you are looking for IS NULL.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.