Re: WHERE creation_date::date > (CURRENT_DATE) - interval '30 days'::date

2020-01-06 Thread Jeremy Evans
On Monday, January 6, 2020 at 9:48:07 AM UTC-8, BeeRich33 wrote:
>
> Any chance I can get some leadership on that statement?  It's one *WHERE* 
> clause I need to use.  
>
> WHERE creation_date::date > (CURRENT_DATE) - interval '30 days'::date
>
> *:creation_date* is a timestamp field.  It's tripping up on the *'30 
> days'* part.  I'm assuming I do not need any coercing to timestamp or 
> datetime types.  
>
> .where(:creation_date > (CURRENT_DATE - interval '30 days')
>
> Cheers
>

"interval" in that context operates similarly to a cast, so this should 
probably work:

.where(Sequel.cast(:creation_date, Date) > Sequel.cast(Sequel::CURRENT_DATE 
- Sequel.cast('30 days', :interval), 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/9f19a321-f1f5-490b-8abe-9ee96aed3e6d%40googlegroups.com.


Re: Select Specific Fields from Dataset

2020-01-06 Thread Jeremy Evans
On Monday, January 6, 2020 at 7:43:16 AM UTC-8, BeeRich33 wrote:
>
> So that is always based on *:id*?
>
> Both look great, but the first I need to remember the select syntax with 
> curly braces and inner array.
>

That's also a shortcut.  Instead of:

select{[:country, count(:id)]}.

You could do:

select(:country, Sequel.function(:count, :id)).

See http://sequel.jeremyevans.net/rdoc/files/doc/virtual_rows_rdoc.html

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/26e19cc6-bd27-4be9-ba20-8c1121027d0a%40googlegroups.com.


WHERE creation_date::date > (CURRENT_DATE) - interval '30 days'::date

2020-01-06 Thread BeeRich33
Any chance I can get some leadership on that statement?  It's one *WHERE* 
clause I need to use.  

WHERE creation_date::date > (CURRENT_DATE) - interval '30 days'::date

*:creation_date* is a timestamp field.  It's tripping up on the *'30 days'* 
part.  I'm assuming I do not need any coercing to timestamp or datetime 
types.  

.where(:creation_date > (CURRENT_DATE - interval '30 days')

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/a28c242d-d4d3-42a9-8d3c-a9d69719952e%40googlegroups.com.


Re: Select Specific Fields from Dataset

2020-01-06 Thread BeeRich33
So that is always based on *:id*?

Both look great, but the first I need to remember the select syntax with 
curly braces and inner array.

-- 
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/970a96a7-3921-4892-84d8-c6f347545979%40googlegroups.com.


Re: Select Specific Fields from Dataset

2020-01-06 Thread Jeremy Evans
On Monday, January 6, 2020 at 5:17:10 AM UTC-8, BeeRich33 wrote:
>
> Hi folks.  How do I select three fields from a dataset?
>
> SELECT country, count(id) FROM "thistable" WHERE ("status" = 'active') 
> GROUP BY "country" ORDER BY "country" DESC
>
>
> Currently I have:
>
> puts DBS[:thistable].where(:status => 'active').group(:country).order(
> Sequel.desc(:country)).sql
>
>
> So I'm missing the *country* and *count(id) *restrictions.  I'm unclear 
> how to add those.  
>

To select specific columns, use Dataset#select:

DBS[:thistable].
  where(:status => 'active').
  select{[:country, count(:id)]}.
  group(:country).
  order(Sequel.desc(:country))

However, Sequel has a shortcut for what you want since it is a common 
operation (assuming id is never NULL):

DBS[:thistable].
  where(:status => 'active').
  group_and_count(:country).
  reverse(:country)

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/d0434b8d-ba75-4183-a9c6-84b875dec1fb%40googlegroups.com.


Re: Select Specific Fields from Dataset

2020-01-06 Thread BeeRich33

Got it.  

puts DBS[:thistable].group_and_count(:country).where(:status => 'active').
order(Sequel.desc(:country)).sql




-- 
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/9cb0f5da-c287-4963-9537-e3ba3cb9390d%40googlegroups.com.


Select Specific Fields from Dataset

2020-01-06 Thread BeeRich33
Hi folks.  How do I select three fields from a dataset?

SELECT country, count(id) FROM "thistable" WHERE ("status" = 'active') 
GROUP BY "country" ORDER BY "country" DESC


Currently I have:

puts DBS[:thistable].where(:status => 'active').group(:country).order(Sequel
.desc(:country)).sql


So I'm missing the *country* and *count(id) *restrictions.  I'm unclear how 
to add those.  

Any insight appreciated.  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/7ebafdc2-39d9-44a8-907a-90428e811109%40googlegroups.com.