On Tue, Nov 15, 2022 at 9:36 AM bee...@gmail.com <beer...@gmail.com> wrote:

> I need to find records where two fields are the same (strings).  I've
> tried a handful of things, but they call come back as 'WHERE false'.
> Here's the two that I thought would work:
>
> puts d.where(Sequel(:field1 == :field2)).to_a.size
> puts d.where(:field1 == :field2).to_a.size
>
> Using a single equals sign throws an error.  I can't seem to find any
> reference to testing two columns, but I looked at Inequality methods, which
> is where I got the first trial above.
>
> Any insights?  Cheers
>

  d.where(:field1 => :field2)

This stems from the fact that symbols represent identifiers, and hashes are
used for equality:

*
http://sequel.jeremyevans.net/rdoc/files/doc/cheat_sheet_rdoc.html#label-Equality
*
http://sequel.jeremyevans.net/rdoc/files/doc/sql_rdoc.html#label-Equality+Operator+-28-3D-29
*
http://sequel.jeremyevans.net/rdoc/files/README_rdoc.html#label-Filtering+Records
*
http://sequel.jeremyevans.net/rdoc/files/doc/sql_rdoc.html#label-Identifiers

Symbol#== doesn't work.  That's defined by Ruby itself to check if two
symbols are equal.  :a == :b should always be false in Ruby code, so the
code you used is the same as .where(false), which explains why you see
WHERE false in the SQL.

Thanks,
Jeremy

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSScW2EZQEEUHRAGow6LPjssFD5K5HbZU5ORvk4K60EWn9A%40mail.gmail.com.

Reply via email to