Re: Is it possible to define a constraint based on the values in other rows in the current table?

From: Glen Huang <heyhgl(at)gmail(dot)com>
To: Hannes Erven <hannes(at)erven(dot)at>
Cc: vinny(at)xs4all(dot)nl, "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Is it possible to define a constraint based on the values in other rows in the current table?
Date: 2017-07-20 02:55:50
Message-ID: D74FED61-DD68-4141-8CDA-7F0D113A34C6@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On 20 Jul 2017, at 5:26 AM, Hannes Erven <hannes(at)erven(dot)at> wrote:
>
> Hi Glen,
>
>
>> I'd like to enforce that in a transaction, after a couple inserts & > updates, a particular column has continuous values like 1, 2, 3, and
> > never any gaps. Is it possible to do?> > I gave a concrete example here: > https://stackoverflow.com/questions/45187113 didn't get any answers yet.
> I've posted a comment to SO; basically what I'm saying is yes, use a transaction constraint trigger to enforce your requirement.
>
> This previous question has an example of such a trigger:
>
> https://stackoverflow.com/a/37277421/1980653
>
>
> HTH & best regards
>
> -hannes

Using a trigger sounds like the right approach. I’ll try it out. Thanks guys.

Hannes, thanks for posting an answer to SO, I’ve accepted it. :)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-07-20 03:01:55 Re: How to stop array_to_json from interpolating column names that weren't there
Previous Message Guyren Howe 2017-07-20 02:30:18 How to stop array_to_json from interpolating column names that weren't there