Thanks!  That worked wonderfully, what it ended up being in the end was the
following.  I had the comparison operator flipped in my because excluded
should win if it is later in time.  Also had to prefix :cached_at with the
table name.

Sequel.expr(:name_cache__cached_at) <= :excluded__cached_at

On Tue, Jul 5, 2016 at 6:01 PM, Jeremy Evans <jeremyeva...@gmail.com> wrote:

> On Tuesday, July 5, 2016 at 3:54:15 PM UTC-7, Ransom Briggs wrote:
>>
>> I am having issues trying to figure out how to do an insert_conflict
>> query with a comparison with an excluded column in the update_where
>> parameter.
>>
>> Here is a simplified version of my table, which is basically just serving
>> as a cache for an external data source.  I have multiple writers so there
>> is a possibility that there may be a collision on the id column.   If there
>> is a collision, I want most recent timestamp I got from my external source
>> to win.  Here is a simplified version of the migration for my table.
>>
>> Sequel.migration do
>>
>>   change do
>>
>>     create_table(:name_cache) do
>>
>>       uuid         :id, primary_key: true
>>
>>       timestamptz  :cached_at, null: false
>>
>>       String       :name, null: false
>>
>>     end
>>
>>   end
>>
>> end
>>
>>
>> And here is what I have so far for my insert_conflict statement.  The
>> problem is that I want to add an update_where option that verifies that
>> :cached_at > :excluded__cached_at but cannot figure out how to do that
>> using the examples in the documentation.  I want to make sure that on
>> conflict that I use the data from the most recent timestamp from my remote
>> source.
>>
>
>> *DB*[:name_cache].insert_conflict(
>>
>>   :target => :id,
>>
>
> :update_where=>Sequel.expr(:cached_at) > :excluded__cached_at,
>
>
>>   :update => {:name => *'*foobar*'*, :cached_at => *'*
>> 2014-01-02T08:00:00Z*'*}
>>
> ).insert_sql(
>>
>>   :id => *'*11111111-1111-1111-1111-111111111111*'*,
>>
>>   :name => *'*foobar*'*,
>>
>>   :cached_at => *'*2014-01-02T08:00:00Z*'*
>>
>> )
>>
> --
> 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.
>

-- 
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.

Reply via email to