Find()ing rows w/ NULL columns?


#1

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

#2

Hi !

2005/12/13, Hugh S. 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 !


#3

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


#4

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.


#5

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

Hi !

2005/12/13, Hugh S. 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 :slight_smile:

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