Thanks for the reply. I've decided to take a different approach. 

But the clarify (incase someone else ends up here). The question was about 
how to convert that block to pure Sequel methods (i.e. actually putting 
that exception in pure SQL). The whole transaction including the exception 
line is all valid postgres SQL. Your suggestion requires you handle the 
exception in Ruby as opposed to handeling the exception inside Postgres. 
For this simple example, handeling it in Ruby actually makes sense. I guess 
the goal was to take another action within Postgres without the return trip.

Caveat: I'm reading that handeling exceptions in Postgres isn't a great 
idea and comes with some performance consequences.

Thanks again.

On Tuesday, April 23, 2013 4:44:10 PM UTC-4, Jeremy Evans wrote:
>
> On Tuesday, April 23, 2013 12:20:24 PM UTC-7, Adam Gotterer wrote:
>>
>> I'm trying to convert the follow query into proper Sequel method calls:
>>
>> BEGIN
>>   INSERT INTO table_x (some_col) VALUES ('some_val');
>> EXCEPTION WHEN unique_violation THEN
>>   -- Ignore duplicate inserts.
>> END;
>>
>> I'm familiar with DB.transaction, but haven't been able to find anything 
>> for the exception syntax outside of handeling the exception within ruby.
>>
>
> The following might work:
>
>   begin
>     DB[:table_x].insert(:some_col=>'some_val')
>   rescue Sequel::UniqueConstraintViolation
>   end
>
> However, unless you are looking for database independent behavior, you may 
> want to keep your plpgsql code.
>
> 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 http://groups.google.com/group/sequel-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to