I've been using the Sequel ORM for a little while and it seems like a
really expressive system for doing database work. Once in a while,
however, I need to make queries where I'm not selecting from the
columns of the database directly, but rather a function of some
columns, e.g. I want to do a count of the number of days for which
records exist in a particular table, for which I would use the
following raw SQL:
select count(distinct date_trunc('day', date)) from my_table;
In my_table, the date column is a timestamp that each row has. The
documentation available seems awfully sparse on how to do this, and so
I'm reduced to using raw SQL to do this sort of thing, rather
unpleasant, and somewhat defeats the purpose of the library itself. I
can't seem to figure out how to replace the * in select * from ...
with something else very easily. There don't seem to be any examples
in the documentation on how to do this properly. The
Sequel::Dataset#select method seems to want actual column names, and I
can't seem to figure ouut how to use the block argument to it, as
there don't seem to be any examples on how to use it or even what a
SQL::VirtualRow class (which it yields) is supposed to do.
Here's another query:
select date_trunc('day', date) as date_, count(*) from my_table group
by date_
to give the number of rows for each day in the table. Any advice on
how to change the select clause of a select statement more generally?
I'm using Postgresql, and Sequel 2.11.0. Thanks in advance for any
advice.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---