Re: Concurrency-safe Replacing a Set of Rows (Without SERIALIZABLE)

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Gavin Wahl <gwahl(at)fusionbox(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Concurrency-safe Replacing a Set of Rows (Without SERIALIZABLE)
Date: 2017-04-12 22:50:18
Message-ID: CAKFQuwanD3ABa=JAeoo3JnbaTiBseTqS8nPNpF2c7owcYR8TMg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Apr 12, 2017 at 3:32 PM, Gavin Wahl <gwahl(at)fusionbox(dot)com> wrote:

> I have a table that stores user notifications:
>
> CREATE TABLE notifications (
> user_id INT,
> type CHAR(1),
> PRIMARY KEY (user_id, type)
> );
> ​[...]​
>
>
> Is there any way to do this correctly without SERIALIZABLE transactions? It
> would be nice to avoid having to retry transactions. Ideally I'd like to
> avoid
> explicit locking as well.
>

​Given this limited example I'd probably choose to model notifications as
an array on the user table. Then just "UPDATE user SET notifications =
array['a','b']::text WHERE user_id = 1;

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gavin Wahl 2017-04-12 22:56:46 Re: Concurrency-safe Replacing a Set of Rows (Without SERIALIZABLE)
Previous Message Adrian Klaver 2017-04-12 22:45:08 Re: Error During PostGIS Build From Source on Linux