Re: [SQL] Unique index VS unique constraint

2013-10-05 Thread JORGE MALDONADO
So, let´s say that I have the following simple example table: 1. cus_id 2. cus_name 3. Other fields . . . Where cus_id is the primary key. And let´s also say that I want cus_name to be unique. I have the option to create a unique constraint or a unique index. What would be the best decision and

Re: [SQL] Unique index VS unique constraint

2013-10-05 Thread Sergey Konoplev
On Sat, Oct 5, 2013 at 3:24 PM, JORGE MALDONADO jorgemal1...@gmail.com wrote: So, let´s say that I have the following simple example table: 1. cus_id 2. cus_name 3. Other fields . . . Where cus_id is the primary key. And let´s also say that I want cus_name to be unique. I have the option

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread luca...@gmail.com
Il 04/10/2013 18:48, JORGE MALDONADO ha scritto: I have search for information about the difference between unique index and unique constraint in PostgreSQL without getting to a specific answer, so I kindly ask for an explanation that helps me clarify such concept. 2 main differences. First

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread Adrian Klaver
On 10/04/2013 09:48 AM, JORGE MALDONADO wrote: I have search for information about the difference between unique index and unique constraint in PostgreSQL without getting to a specific answer, so I kindly ask for an explanation that helps me clarify such concept. The way I think of it is, that

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread Adrian Klaver
On 10/04/2013 10:41 AM, luca...@gmail.com wrote: Il 04/10/2013 18:48, JORGE MALDONADO ha scritto: I have search for information about the difference between unique index and unique constraint in PostgreSQL without getting to a specific answer, so I kindly ask for an explanation that helps me

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread David Johnston
JORGE MALDONADO wrote I have search for information about the difference between unique index and unique constraint in PostgreSQL without getting to a specific answer, so I kindly ask for an explanation that helps me clarify such concept. A constraint says what valid data looks like. An

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread Steve Grey
Unique indexes can be partial, i.e. defined with a where clause (that must be included in a query so that PostgreSQL knows to use that index) whereas unique constraints cannot. JORGE MALDONADO wrote I have search for information about the difference between unique index and unique constraint in

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread David Johnston
Steve Grey-2 wrote Unique indexes can be partial, i.e. defined with a where clause (that must be included in a query so that PostgreSQL knows to use that index) whereas unique constraints cannot. This implies there can be data in the table but not in the index and thus said index is not part

Re: [SQL] Unique index and unique constraint

2013-07-27 Thread Dmitriy Igrishin
2013/7/27 Alvaro Herrera alvhe...@2ndquadrant.com PostgreSQL implements unique constraints by way of unique indexes (and it's likely that all RDBMSs do likewise). Also, the syntax to declare unique indexes allows for more features than the unique constraints syntax. For example, you can

Re: [SQL] Unique index and unique constraint

2013-07-26 Thread Luca Vernini
I try to explain my point of view, also in my not so good English: A primary key is defined by dr. Codd in relational model. The key is used to identify a record. In good practice, you must always define a primary key. Always. The unique constraint will simply say: this value (or combination)

Re: [SQL] Unique index and unique constraint

2013-07-26 Thread Alvaro Herrera
JORGE MALDONADO escribió: I guess I am understanding that it is possible to set a unique index or a unique constraint in a table, but I cannot fully understand the difference, even though I have Google some articles about it. I will very much appreciate any guidance. The SQL standard does not

Re: [SQL] Unique index and unique constraint

2013-07-26 Thread Sergey Konoplev
On Fri, Jul 26, 2013 at 3:19 PM, Alvaro Herrera alvhe...@2ndquadrant.com wrote: JORGE MALDONADO escribió: I guess I am understanding that it is possible to set a unique index or a unique constraint in a table, but I cannot fully understand the difference, even though I have Google some