Thread: "UNIQUE" not recognized when another attribute is declared as "PRIMARY KEY"
"UNIQUE" not recognized when another attribute is declared as "PRIMARY KEY"
From
"Herr Dumont"
Date:
============================================================================ POSTGRESQL BUG REPORT TEMPLATE ============================================================================ Your name : RP. Dumont Your email address : dumont@gmx.net System Configuration --------------------- Architecture (example: Intel Pentium) : Intel Pentium MMX Operating System (example: Linux 2.0.26 ELF) : Linux 2.2.5 ELF (i386) PostgreSQL version (example: PostgreSQL-6.5.1) : PostgreSQL-6.5.1 Compiler used (example: gcc 2.8.0) : gcc egcs-2.91.66 Please enter a FULL description of your problem: ------------------------------------------------ When a table is created using "CREATE TABLE" and one attribute is declared as "PRIMARY KEY", the word "UNIQUE" has no effect on another attribute (i.e. no implicit index is created for the "UNIQUE" attribute and it is possible to add several records with the same value for the "UNIQUE" attribute). PostgreSQL 6.4.2 did not have any problem with that. Please describe a way to repeat the problem. Please try to provide a concise reproducible example, if at all possible: ---------------------------------------------------------------------- First connect to a database: psql mydb Then create the following table: CREATE TABLE mytest ( x INTEGER PRIMARY KEY, y VARCHAR(20) UNIQUE ); Now it is possible to insert this: INSERT INTO mytest VALUES (1,´test´); INSERT INTO mytest VALUES (2,´test´); although this should not be possible, because y was declared as "UNIQUE" ! This problem only occurs when one attribute is a "PRIMARY KEY". If you know how this problem might be fixed, list the solution below: ---------------------------------------------------------------------