Re: Restrictions for a specific situation in my DB - Mailing list pgsql-novice

From Laurenz Albe
Subject Re: Restrictions for a specific situation in my DB
Date
Msg-id 9a0d712598b38a190c81da043b5e9620d54a96b3.camel@cybertec.at
Whole thread Raw
In response to Re: Restrictions for a specific situation in my DB  (JORGE MALDONADO <jorgemal1960@gmail.com>)
List 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




pgsql-novice by date:

Previous
From: JORGE MALDONADO
Date:
Subject: Re: Restrictions for a specific situation in my DB
Next
From: Nam Nguyen
Date:
Subject: connect to postgresql Server via two gateway Traffic Server instancesusing explicit proxying