On Thursday, June 21, 2018 at 10:41:52 AM UTC-7, lkfken wrote:
>
> Hi Jeremy,
>
> Sorry about that. I misunderstood on what you need.
>
> Here is the SQL statement 
> SELECT NAME, 
>        dates, 
>        source 
> FROM   (SELECT NAME, 
>                a_date, 
>                b_date, 
>                c_date 
>         FROM   test 
>         WHERE  NAME = 'TOM') AS p1 
>        UNPIVOT ( dates 
>                FOR source IN (a_date, 
>                               b_date, 
>                               c_date) ) AS p2; 
>
> so what I want is to have "p1" come from Sequel::Dataset (ie: Test.toms, 
> Test.joes, etc) instead of hard code it into this SQL statement.
>

This should work, and produce the same SQL (modulo identifier quoting):

 DB.select(:NAME, :dates, :source).
  from(DB[:test].select(:NAME, :a_date, :b_date, 
:c_date).where(:name=>'TOM').as(:p1),
       Sequel.lit("UNPIVOT (dates FOR source IN (a_date, b_date, 
c_date))").as(:p2))

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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to