public inbox for [email protected]
help / color / mirror / Atom feedFrom: chidamparam muthusamy <[email protected]>
To: [email protected]
Cc: Pgsql Novice <[email protected]>
Subject: Re: How to use a cross column exclude constraint
Date: Tue, 23 Aug 2022 20:17:46 +0530
Message-ID: <CABUk_4iSF9MagtgSX9ox5ZOqX0hMLo+FVN=xcJHksSW=aUriHQ@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
Refer https://www.postgresql.org/docs/current/ddl-constraints.html
CREATE TABLE products (
product_no integer,
name text,
price numeric CHECK (price > 0),
discounted_price numeric CHECK (discounted_price > 0),
CHECK (price > discounted_price)
);
In the above example, column 'discounted_price' value is checked that it
should be less than the column value, 'price'.
Is it possible to add similar check condition for the columns,
'record_a_id' and 'record_b_id' that is
CHECK(record_a_id != record_b_id)
Regards,
Chidamparam
On Mon, Aug 22, 2022 at 1:15 AM <[email protected]> wrote:
>
> Hi All,
>
> Schema:
>
> CREATE TABLE record (
> id uuid primary key default ...,
> ...
> );
>
> CREATE TABLE record_pointer (
> id uuid primary key default ...,
> record_a_id uuid not null references record (id),
> record_b_id uuid not null references record (id),
> ...
> );
>
>
> I am trying to create an exclude constraint to make both record_a_id and
> record_b_id unique table wide, so that each row from "record" can ever be
> referenced once in "record_pointers".
>
> Eg. if I add a record_pointer row that has "this-is-random-uuid" as
> record_a_id, the value "this-is-random-uuid" can never be in record_a_id or
> record_b_id in any other row.
>
>
> Thank you in advance!
>
>
>
view thread (7+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: How to use a cross column exclude constraint
In-Reply-To: <CABUk_4iSF9MagtgSX9ox5ZOqX0hMLo+FVN=xcJHksSW=aUriHQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox