On Friday, April 6, 2018 at 1:44:55 PM UTC-7, Ransom Briggs wrote: > > Hello, > > I have an insert statement that is inserting values selected from another > table based on some filters. I am trying to convert this to a prepared > statement, but from what I can tell, the prepared statement version of > insert > <https://github.com/jeremyevans/sequel/blob/master/doc/prepared_statements.rdoc#prepared-statements> > > only works for inserts of the the type "INSERT INTO ... VALUES. Is there > an easy way that I could turn an insert like the following into a prepared > statement? > > DB[:bar].insert([:foo_id], DB[:foo].select(:id).where(biz: true)) # INSERT > INTO "bar" ("foo_id") SELECT "id" FROM "foo" WHERE ("biz" IS TRUE) > > Thanks, > Ransom >
Bound variables: DB[:bar].call(:insert, {:biz=>1}, [:foo_id], DB[:foo].select(:id).where(biz: :$biz)) Prepared statements: ps = DB[:bar].prepare(:insert, :insert_foo, [:foo_id], DB[:foo].select(:id).where(biz: :$biz)) ps.call(:biz=>true) DB.call(:insert_foo, :biz=>true) 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 post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.