On Tuesday, January 7, 2020 at 7:01:05 AM UTC-8, BeeRich33 wrote:
>
> Trying to avoid *fetch* (which isn't working either), I have the
> following attempt for sequel:
>
> SELECT hashtag, (tagcount/1000) AS tagcount
> FROM myhashtags
> WHERE status = 'new'
> AND NOT hashtag = ANY (?)
> ORDER BY tagcount DESC
> LIMIT ? }, 'active', avoids, 29 ]
>
> This is what I have:
>
> DBL[:myhashtags].
> where(:status => 'active').
> select{ :hashtag, (Sequel.function(:tagcount/1000)) }. # => trouble
> here
> reverse(:tagcount).
> limit(29)
>
>
>
> My *avoids* is a list of tags to not include (avoid). I can't seem to
> get the *:tagcount/1000* to work either. I can't seem to find anything
> in the docs that shows me how to get that done.
>
select(:hashtag, (Sequel[:tagcount]/1000).as(:tagcount))
or:
select{[:hashtag, (tagcount/1000).as(:tagcount)]}
This is documented:
http://sequel.jeremyevans.net/rdoc/files/doc/sql_rdoc.html#label-Standard+Mathematical+Operators+-28-2B+-+-2A+-2F-29
> Any insight appreciated as to how I can get this to work. Even .fetch
> isn't working.
>
I'm guessing fetch isn't working because of the ANY expression. You might
need to avoid the parentheses around the placeholder. I also only see two
placeholders in your SQL, but you have three placeholder values. Maybe
'new' is supposed to be ? in your SQL?
Here's a translation of the query to Sequel:
DB[:myhashtags].
select{[:hashtag, (tagcount/1000).as(:tagcount)]}.
where(:status=>'new').
exclude{{:hashtag=>ANY(*avoids)}}.
reverse(:tagcount).
limit(29)
Which results in the following SQL (modulo whitespace), assuming avoids is
[1,2,3]:
SELECT "hashtag", ("tagcount" / 1000) AS "tagcount"
FROM "myhashtags"
WHERE (("status" = 'new')
AND NOT ("hashtag" = ANY(1, 2, 3)))
ORDER BY "tagcount" DESC
LIMIT 29
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/f86f3339-105a-4d44-85ae-6edc6a295990%40googlegroups.com.