On Thursday, March 10, 2016 at 4:26:07 PM UTC-8, John Barker wrote:
>
> Apologies if this has already been asked and/or answered (I did
> extensively search the documentation, github issues and this group).
>
> Is it possible to use `insert_conflict` with `import` using Postgres? I'm
> wanting to efficiently bulk add items, but I do have unique constraints in
> place that I need to account for and handle accordingly. Currently, I'm
> running with the following idea (but have yet to test):
>
> DB[:table]
>> .insert_conflict(
>> constraint: :table_a_uniq_idx,
>> update: {
>> a: :excluded__a
>> }
>> )
>> .import([:a, :b], [['a', 'b'], ['a', 'c']])
>>
>
I don't think it will work due to a PostgreSQL restriction:
Sequel::DatabaseError: PG::CardinalityViolation: ERROR: ON CONFLICT DO
UPDATE command cannot affect row a second time
However, assuming that values for the 'a' column are unique in the imported
data, which you should be able to check before using them, it will update
existing matching rows already in the table.
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.