On Wednesday, December 30, 2015 at 9:24:40 AM UTC-8, [email protected] 
wrote:
>
> Back in July I had asked and received helpful suggestions about doing 
> "Conditional INSERT to PostgreSQL" [1].  I'm now trying to take advantage 
> of the PostgreSQL 9.5 "ON CONFLICT" feature as a solution.  Starting with 
> the simplest case, I previously had as a Model ClassMethod and peer to 
> create():
>
>     def create?( h )
>>       create( h )
>>     rescue Sequel::UniqueConstraintViolation => e
>>       nil
>>     end
>>
>
> This gave the desired behavior on the client side, but results in 
> undesired error logging and some associated overhead on the Postgres server 
> side.  Using Sequel 4.29 and Postgres 9.5, I can replace the above with:
>
>     def create?( h )
>>       c = dataset.returning.insert_ignore.insert( h ).first
>>       c && call( c )
>>     end
>>
>
> This works great for the simple cases, but is failing with PG syntax 
> errors in cases where I had also been using the pg_array and pg_json 
> extensions for mapping columns of those types.  Is there some better way to 
> hook into the model level column mapping (and extensions) while using this 
> dataset level insert_ignore feature? 
>

This will probably work for what you want:

 def create?( h )
   c = dataset.returning.insert_ignore.insert(new(h).values).first
   c && call( c )
 end

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