On Sun, Feb 15, 2015 at 08:53:28AM -0800, Jeremy Evans wrote:
> On Sunday, February 15, 2015 at 12:52:27 AM UTC-8, Matt Palmer wrote:
> > Long version: 
> >
> > I tried to define a where clause which contained a modulus calculation, 
> > like 
> > so: 
> >
> >     db[:ex].where { col % 3 == 0 } 
> >
> > Much to my surprise, this bombed, telling me 
> >
> >     NoMethodError: undefined method `%' for #<Sequel::SQL::Identifier 
> > @value=>:col> 
> >
> 
> This is wrong in two places.  First, equality is done via hashes, second, 
> the modulus operator is only defined for columns known to be numeric.
> 
>   db[:ex].where{{col.sql_number % 3 => 0}}

Fair enough.  Why does modulo need to be called against a numeric column,
while the other arithmetic-only operators can be applied to anything?  I get
why '+' is valid for strings (nice one, by the way), but the others aren't
valid Ruby for Strings.

> > "Hmm, OK", says I, "I'll see if I'm doing this totally wrong, by trying 
> > division": 
> >
> >     db[:ex].where { col / 3 == 0 } 
> >
> > This doesn't exception out, but instead produces the SQL 
> >
> >     SELECT * FROM "ex" WHERE false 
> >
> > That's... not right. 
> 
> Sequel doesn't override the equality operator (#==), as that would make it 
> very difficult to determine equality at the ruby level.

With the example you provide, I now understand why #== can't be overridden.

> I'd definitely welcome documentation updates that better explain things, 
> though.

Then that is the patch I shall endeavour to produce.

Thanks,
- Matt

-- 
I am cow, hear me moo, I weigh twice as much as you. I'm a cow, eating
grass, methane gas comes out my ass. I'm a cow, you are too; join us all!
Type apt-get moo.

-- 
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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to