I am working on a query that has case statement that gives values based on 
the age of a field.  I have it working, but I just want to see if this is 
the best way to accomplish it.

    Sequel.case([
      [Sequel.expr {Sequel.function(:age, :last_seen) <= 
Sequel.lit("interval '1 months'")}, 10],
      [Sequel.expr {Sequel.function(:age, :last_seen) <= 
Sequel.lit("interval '3 months'")},  5]
    ], 0)

I'm giving 10 points to last_seen less than 1 month ago, 5 points less than 
3 months ago, and zero points otherwise.  The generated case statement 
would look something like:

case
when age(last_seen) <= interval '1 month' then 10
when age(last_seen) <= interval '3 months' then 5
else 0
end

I would prefer to eliminate the Sequel.lit("interval..") method calls if I 
can (is this something the pg_interval plugin would handle). 

Does this seem like the best approach?

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to