Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a table and I need to select all the rows with an empty value for the fk_fc_id field (as a prelude to deleting them),

    Column     |            Type             |                         Modifiers
 di_timestamp  | timestamp without time zone |
 di_item_value | character varying(10)       |
 fk_fc_id      | integer                     |
 di_id         | integer                     | not null default nextval('data_item_di_id_seq1'::regclass)

However this doesn't work,

# select fk_fc_id,di_timestamp,di_item_value from data_item where fk_fc_id="";
ERROR:  zero-length delimited identifier at or near """"
LINE 1: ...di_timestamp,di_item_value from data_item where fk_fc_id="";

Trying Null doesn't work either.

If anyone has any suggestions on how to sort this, I would be very grateful.

share|improve this question
select fk_fc_id,di_timestamp,di_item_value from data_item where fk_fc_id is null – foibs Dec 3 '13 at 12:57
Double quotes aren't used for strings in PostgreSQL. Single quotes are used for strings. But you shouldn't be comparing zero-length strings to integers! And comparing values with null using the = operator will always return null and cause that row to be excluded. – Colin 't Hart Dec 3 '13 at 13:27
up vote 9 down vote accepted

This is not really database administration related, nor is it really about PostgreSQL, but as @foibs answered, you should have a look at IS NULL:

 SELECT fk_fc_id,
 FROM data_item  
 WHERE fk_fc_id IS NULL
share|improve this answer
Ah, I was trying = Null rather than is Null. Thanks, – James Dec 3 '13 at 13:53

Your Answer


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.