Re: Restrictions for a specific situation in my DB

Laurenz Albe <laurenz.albe@cybertec.at>

From: Laurenz Albe <laurenz.albe@cybertec.at>
To: JORGE MALDONADO <jorgemal1960@gmail.com>, pgsql-novice <pgsql-novice@postgresql.org>
Date: 2020-05-13T20:26:53Z
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