I'm trying to run an update similar to this:

UPDATE table AS n
SET field = 'a'
FROM (SELECT ... ) AS o
WHERE n.key = o.key

(PostgreSQL 9.1, Sequel 3.45.0)

The following code fails with "Need multiple FROM tables if updating/deleting a 
dataset with JOINs"

    ds0 = MDB[:show_interaction_bindings].
      exclude(like_or_favorite: true).
      filter(interaction_text: "Liked").
      filter("interaction_created_at >= :start_at AND interaction_created_at < 
:end_at", start_at: date, end_at: date + 1).
      select(:interaction_created_at, :market_id, :show_id, 
:interaction_service_id, :service_name).
      limit(5000)

    count = MDB[:show_interaction_bindings].
      inner_join(ds0, [:interaction_created_at, :market_id, :show_id, 
:interaction_service_id, :service_name]).
      update(like_or_favorite: true)

I wrote the SQL query myself, but then couldn't find an obvious method that 
returned the count. I did find #execute_dui, but the docs say "should not be 
called from user code". #execute_dui is called from #update, but then I don't 
see how to pass in all the options I need.

I'd like to see an example of doing an update with a join, or multiple from 
tables.

Is it possible for Sequel to "just work" with the query I wrote above? I really 
expected that to work out of the box.

Thanks,
François Beausoleil

-- 
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 post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to