# Find()ing rows w/ NULL columns?

**URL:** <https://www.ruby-forum.com/t/find-ing-rows-w-null-columns/50164>\
**Category:** Rails\
**Created:** [December 13, 2005, 8:43pm UTC](https://www.ruby-forum.com/t/find-ing-rows-w-null-columns/50164 "2005-12-13T20:43:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [December 13, 2005, 8:43pm UTC](https://www.ruby-forum.com/t/find-ing-rows-w-null-columns/50164/1 "2005-12-13T20:43:01Z")

</div>

Agile Web D. with Rails doesn’t seem to have NULL in the  
index [or my eyes have failed me again], and web searching turns up  
lots of SQL statements containing NOT NULL.

I have a table of loans, and I want to record when something was  
loaned and returned. The loan date can’t be null, or there’d be  
no entry in the table. The return date must be something until  
the item is returned, and NULL seems a sensible sentinal value.

How does one  
Loan.find(:all, :conditions =\> [":return = ?" , something])  
to pick up the null entries, thus items that haven’t been returned?  
I’m thinking that “:return = NULL” might match a string “NULL”, but  
can’t find confirmation or denial of this…

Maybe there’s another idiom for this kind of problem? (Setting a  
return date in the year 3000 seems like a bodge, and it would  
overflow Unix ideas of time anyway…)

```
    Thank you,
    Hugh
```

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [December 13, 2005, 8:46pm UTC](https://www.ruby-forum.com/t/find-ing-rows-w-null-columns/50164/2 "2005-12-13T20:46:04Z")

</div>

Hi !

2005/12/13, Hugh S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> How does one  
> Loan.find(:all, :conditions =\> [“:return = ?” , something])  
> to pick up the null entries, thus items that haven’t been returned?  
> I’m thinking that “:return = NULL” might match a string “NULL”, but  
> can’t find confirmation or denial of this…

Load.find(:all, :conditions =\> ‘return IS NULL’)

Also, note that in your original code you put ‘:return’ (note the  
colon). That would have given you an error since Rails would have  
tried to replace :return with a value, but would not have found  
anything in something (not being a Hash).

Hope that helps !

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [December 13, 2005, 8:46pm UTC](https://www.ruby-forum.com/t/find-ing-rows-w-null-columns/50164/3 "2005-12-13T20:46:04Z")

</div>

> How does one  
> Loan.find(:all, :conditions =\> [“:return = ?” , something])  
> to pick up the null entries, thus items that haven’t been returned?  
> I’m thinking that “:return = NULL” might match a string “NULL”, but  
> can’t find confirmation or denial of this…

Loan.find(:all, :conditions =\> ‘return IS NULL’)

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [December 13, 2005, 8:58pm UTC](https://www.ruby-forum.com/t/find-ing-rows-w-null-columns/50164/4 "2005-12-13T20:58:06Z")

</div>

Am Dienstag, den 13.12.2005, 19:41 +0000 schrieb Hugh S.:

> Loan.find(:all, :conditions =\> [":return = ?" , something])  
> to pick up the null entries, thus items that haven’t been returned?  
> I’m thinking that “:return = NULL” might match a string “NULL”, but  
> can’t find confirmation or denial of this…
> 
> Maybe there’s another idiom for this kind of problem? (Setting a  
> return date in the year 3000 seems like a bodge, and it would  
> overflow Unix ideas of time anyway…)
> 
> ```
> Thank you,
> Hugh
> 
> ```

If you want to find all records with NULL values in field return use  
this line:

Loan.find(:all, :conditions =\> ‘return IS NULL’)

Don’t know if this is exactly what you wanted.

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [January 1, 2006, 9:33pm UTC](https://www.ruby-forum.com/t/find-ing-rows-w-null-columns/50164/5 "2006-01-01T21:33:48Z")

</div>

On Tue, 13 Dec 2005, Francois B. wrote:

> Hi !

2005/12/13, Hugh S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > How does one  
> > Loan.find(:all, :conditions =\> [“:return = ?” , something])  
> > to pick up the null entries, thus items that haven’t been returned?  
> > I’m thinking that “:return = NULL” might match a string “NULL”, but  
> > can’t find confirmation or denial of this…
> 
> Load.find(:all, :conditions =\> ‘return IS NULL’)

thank you, and the others who said the same.

> Also, note that in your original code you put ‘:return’ (note the  
> colon). That would have given you an error since Rails would have

Thank you, I was too hasty in composing that 🙂

> tried to replace :return with a value, but would not have found  
> anything in something (not being a Hash).
> 
> ## Hope that helps !
> 
> FranÃ§ois Beausoleil

```
    Hugh

```
