On Wednesday, January 8, 2020 at 9:33:55 AM UTC-8, BeeRich33 wrote:
>
>
>> My apologies for correcting you yet again, hence the questions here in 
> the group meant for such questions:
>
> DBS[:searches_t].
>     where{(exclude(search_phrase: nil))}.
>     select(:search_phrase, :result_count)
>
>
> ERROR.  *HINT:  No function matches the given name and argument types. 
> You might need to add explicit type casts. *Points to "exclude"
>
> The "Where TRUE" is what the .sql is explaining.  From here:
>
> where{(exclude(:search_phrase = nil) & (:client_ip != '192.168.1.4')}.
>
>
This doesn't work for multiple reasons.  I don't even think it is valid 
ruby syntax (:search_phrase = nil).  Even if you fixed the Ruby syntax 
issues, you don't want to call exclude inside where, as it isn't an SQL 
function, and :client_ip != '192.168.1.4' is always going to be true, since 
a Ruby symbol is not ever equal to a Ruby string.
 

> Question still not answered.  I've simplified the query to the following, 
> which still has no answer:
>
> DBS[:searches_t].
>     where{(exclude(search_phrase: nil))}.
>     select(:search_phrase, :result_count)
>

Here you are using the virtual row syntax to call the exclude SQL function, 
except that exclude is not an SQL function.  You want to call 
exclude(search_phrase: nil) instead of where{(exclude(search_phrase: nil)

 I've also tried:

> DBS[:searches_t].
>     where{(:search_phrase != nil)}.
>     select(:search_phrase, :result_count)
>
> => provides nils.  So that doesn't work.
>

A Ruby symbol will never equal nil.  You could possibly use 
where{search_phrase !~ nil}, though the exclude example given above is more 
idiomatic.
 

>
> I've also tried:
>
> DBS[:searches_t].
>     where{(:search_phrase !~ nil)}.
>     select(:search_phrase, :result_count)
>
> => provides nils.  Doesn't work.  
>

Sequel doesn't override Symbol#!~ (or any core Ruby methods by default).  
(:search_phrase 
!~ nil) returns true, so the where call is the same as where{true}
 

> I'm reading as much as I can, and wish to avoid coming in here.  Believe 
> me.  
>

While the documentation covers the issues you have brought up, it does not 
directly address your particular use case.  The documentation does assume 
an intermediate level understanding of the Ruby language, so it doesn't 
directly explain why only one of the following gives you the results that 
you want:

where{:search_phrase != nil}
where{:search_phrase !~ nil}
where{search_phrase != nil}
where{search_phrase !~ nil}

In short, :search_phrase and search_phrase are different here, with 
:search_phrase being a Ruby symbol and search_phrase being a method call 
that returns a Sequel-specific object.  That object implements !~ but not 
!=, as overriding != would break Ruby-level equality.

You should be aware that this is a help forum for the Sequel library, not a 
forum to help you with your specific project.  You should try to keep your 
requests for help generic (unrelated to your project), and as minimal as 
possible for the topic you have a question about.  It would probably be 
best if you could always post the SQL you are trying to generate, and ask 
how to represent it in Sequel, as that minimizes the potential problems.

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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/1622db1f-81b8-412c-8bdf-54514bd648fd%40googlegroups.com.

Reply via email to