Re: Restrictions for a specific situation in my DB
JORGE MALDONADO <jorgemal1960@gmail.com>
From: JORGE MALDONADO <jorgemal1960@gmail.com>
To: pgsql-novice <pgsql-novice@postgresql.org>
Date: 2020-05-13T14:10:03Z
Lists: pgsql-novice
*"You should always CC the list."* I am sorry for that. I will take it into consideration from now on. *"I have never heard of a "restriction" as a technical concept in databases,so I cannot answer that."* 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. With respect, Jorge Maldonado On Tue, May 12, 2020 at 10:46 PM Laurenz Albe <laurenz.albe@cybertec.at> wrote: > On Tue, 2020-05-12 at 18:27 -0500, JORGE MALDONADO wrote: > > You should always CC the list. > > > Does it has to be a UNIQUE INDEX? > > If you want to avoid duplicates, yes. > > > What about a RESTRICTION? I understand it also creates a UNIQUE INDEX > behind the scenes. > > Is a RESTRICTION not supported because of the LEAST and GREATEST > expressions? > > If it is, what is a reason to use a UNIQUE INDEX instead of a > RESTRICTION? > > I just want to fully understand the concept. > > I have never heard of a "restriction" as a technical concept in databases, > so I cannot answer that. > > Yours, > Laurenz Albe > -- > +43-670-6056265 > Cybertec Schönig & Schönig GmbH > Gröhrmühlgasse 26, A-2700 Wiener Neustadt > Web: https://www.cybertec-postgresql.com > >