Re: Restrictions for a specific situation in my DB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>, pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Restrictions for a specific situation in my DB
Date: 2020-05-13 20:26:53
Message-ID: 9a0d712598b38a190c81da043b5e9620d54a96b3.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, 2020-05-13 at 09:10 -0500, JORGE MALDONADO wrote:
> What I meant was "CONSTRAINT". I understand that, in PostgreSQL, I can define "UNIQUE INDEX"
> and "UNIQUE CONSTRAINT" and that a "UNIQUE CONSTRAINT" creates a "UNIQUE INDEX" behind the scenes.
>
> So my question is:
> Can a "UNIQUE CONSTRAINT" be used instead of a "UNIQUE INDEX"?
>
> I searched the web for an answer and found that expressions like LEAST and GREATEST are
> not allowed in a UNIQUE CONSTRAINT but they can be used in a UNIQUE INDEX. I also tested
> directly in a table and I could verify it. So, a UNIQUE INDEX is the choice to include
> LEAST and GREATEST.

You got it.
A unique constraint can only be defined on columns, not on expressions.
But unique indexes can have an expression as key.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Nam Nguyen 2020-05-19 23:46:02 connect to postgresql Server via two gateway Traffic Server instances using explicit proxying
Previous Message JORGE MALDONADO 2020-05-13 14:10:03 Re: Restrictions for a specific situation in my DB