Re: Variable into Sequel.cast
On Monday, January 20, 2020 at 11:53:45 AM UTC-8, BeeRich33 wrote: > > OK, it was apparently working for me somehow. Anyway, in Sequel, is this > the proper sequence for a var placeholder? It works but I'm confused about > the *:interval* casting type, and its position within that Sequel.cast: > > where(Sequel.cast(:login_date, Date) > Sequel.cast(Sequel::CURRENT_DATE - > Sequel.cast((? 'days', 30) :interval), Date)) > > > where(Sequel.cast(:login_date, Date) > Sequel.cast(Sequel::CURRENT_DATE - Sequel.cast(Sequel.lit("'? days'", 30), :interval), Date)) or: .where(Sequel.cast(:login_date,Date) > (Sequel::CURRENT_DATE - (Sequel[30.to_s] + ' days').cast(:interval)).cast(Date)) 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/35d516fe-ca17-47b1-bcce-8cc779d3ba7d%40googlegroups.com.
Re: Variable into Sequel.cast
OK, it was apparently working for me somehow. Anyway, in Sequel, is this the proper sequence for a var placeholder? It works but I'm confused about the *:interval* casting type, and its position within that Sequel.cast: where(Sequel.cast(:login_date, Date) > Sequel.cast(Sequel::CURRENT_DATE - Sequel.cast((? 'days', 30) :interval), Date)) Cheers -- 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/22c08ffe-9a03-42cd-b56b-b719fb752240%40googlegroups.com.
Re: Variable into Sequel.cast
On Sunday, January 19, 2020 at 8:56:04 PM UTC-8, BeeRich33 wrote: > > This is how I've been using it, now currently replaced with "30 days" > manually. I'd like to shove a variable in there. > > tm = PG::TypeMapByColumn.new([ > PG::TextEncoder::String.new > ]) > d = d.to_s > > res = $conn.exec_params( %Q{ SELECT search_phrase, count(search_phrase) > FROM searches > WHERE creation_date::timestamp::date > (CURRENT_DATE - interval '$1 > days')::date > AND search_phrase != 'about' > GROUP BY search_phrase > ORDER BY count(search_phrase) DESC }, [ d ], 0, tm ).to_a > > > I'm trying something similar and I can't get it to work ($conn is a PG::Connection instance): $conn.exec_params("SELECT CURRENT_DATE - interval '$1 days' as b", ['30'], 0, tm) PG::IndeterminateDatatype (ERROR: could not determine data type of parameter $1) It's not difficult to work around though: $conn.exec_params("SELECT CURRENT_DATE - ($1 || ' days')::interval as b", ['30']).to_a [{"b"=>"2019-12-21 00:00:00"}] 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/6f9ed0f7-5231-4238-8b29-b94409231b49%40googlegroups.com.
Re: Variable into Sequel.cast
This is how I've been using it, now currently replaced with "30 days" manually. I'd like to shove a variable in there. tm = PG::TypeMapByColumn.new([ PG::TextEncoder::String.new ]) d = d.to_s res = $conn.exec_params( %Q{ SELECT search_phrase, count(search_phrase) FROM searches WHERE creation_date::timestamp::date > (CURRENT_DATE - interval '$1 days')::date AND search_phrase != 'about' GROUP BY search_phrase ORDER BY count(search_phrase) DESC }, [ d ], 0, tm ).to_a -- 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/37db9845-c5bc-4771-af53-83cef8ee29da%40googlegroups.com.
Re: Variable into Sequel.cast
On Wednesday, January 8, 2020 at 8:00:36 AM UTC-8, BeeRich33 wrote: > > My PG syntax has a variable into an interval: > > WHERE creation_date::timestamp::date > (CURRENT_DATE - interval '$1 days' > )::date > That's interesting, it's not something I would expect to work because the placeholder is inside an SQL string. It certainly doesn't work when using psql: > PREPARE foo AS SELECT (CURRENT_DATE - interval '$1 days')::date; PREPARE > EXECUTE foo(2); date 2020-01-07 > EXECUTE foo(10); date 2020-01-07 Can you provide some example ruby code that shows this variable working? I can only assume it's some ruby library using broken interpolation. > Can I use a variable in Sequel as a parameter passed to this method, for > use inside this interval integer? > > Sequel.cast('? days', 30, :interval) > You could probably do this type of string interpolation in Ruby: num_days = 30 Sequel.cast("#{num_days} days", :interval) 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/ef96a338-5b67-4fdb-83a4-123e180a6464%40googlegroups.com.
Variable into Sequel.cast
My PG syntax has a variable into an interval: WHERE creation_date::timestamp::date > (CURRENT_DATE - interval '$1 days'):: date Can I use a variable in Sequel as a parameter passed to this method, for use inside this interval integer? Sequel.cast('? days', 30, :interval) -- 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/5df736c2-1ac7-4314-a030-7b07ee27b40c%40googlegroups.com.