Are there any built-in API to allow batch updates with support for PostgreSQL?

I'm looking for something like Dataset#import.

Here's how the batch update sql could look like:

UPDATE table_name SET col1 = v.c1, col2 = v.c2
  FROM (VALUES (10, 'a', 200), (20, 'c', 300)) AS v (id, c1, c2)
  WHERE table_name.id = v.id;

In case there's no built-in API for this, what would be the recommended approach for generating such SQL while taking care of the proper values escaping procedures?

In case you're interested in the use-case, I'm creating an import procedure to integrate with a third-party partner and I need to implement an upsert/merge strategy. Since PG doesn't support it out-of-the-box, I'm doing something like this:

DB[some_table].lock(:exclusive) do
# some code to filter existent and inexistent entries using a single query
  DB[some_table].import columns, inexistent_entries
DB[some_table].batch_update columns, existent_entries_with_id # yet to be implemented
end

Any guidance is appreciated.

Thanks in advance,
Rodrigo.

--
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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to