On Tuesday, December 4, 2018 at 9:44:58 AM UTC-8, Eric Promislow wrote:
>
>
> …
>> You could probably try:
>>
>>   ProcessModel.db.from(Sequel[:processes].as(:p1), 
>> Sequel[:processes].as(:p2))
>>
>> Thanks,
>> Jeremy
>>
>
> The generated SQL doesn't make sense, for both Postgres and MySQL:
>
> ProcessModel.db.from{[Sequel[:processes].as(:p1), 
> Sequel[:processes].as(:p2)]}.
>     where{(p1[:app_guid] =~ p2[:app_guid]) & (p1[:created_at] < 
> p2[:created_at])}.
>     distinct.select{p1[:guid]}
>
> maps to
>
> #<Sequel::Mysql2::Dataset: "SELECT DISTINCT `p1`.`guid` WHERE (`processes` 
> AS `p1` AND `processes` AS `p2` AND (`p1`.`app_guid` = `p2`.`app_guid`) AND 
> (`p1`.`created_at` < `p2`.`created_at`))">
>
> I think the problem is the lack of a FROM clause in the query.
>
> This happens with both Postgres and MySQL
>

I explained in my previous message that the original code I gave was for 
the current version of Sequel.  Then I gave code at the bottom with 
something that will work in Sequel 4.  You apparently chose to ignore the 
new code fragment (despite quoting it) and responded with the original code 
and the SQL generated.

Maybe it wasn't obvious how to integrate the code fragment I gave for 
Sequel 4 into the original code? I guess a more complete example may be 
helpful to you.  Please try this:

ProcessModel.db.from(Sequel[:processes].as(:p1), 
Sequel[:processes].as(:p2)).
  where{(p1[:app_guid] =~ p2[:app_guid]) & (p1[:created_at] < 
p2[:created_at])}.
  distinct.
  select{p1[:id]}

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