BUG #1698: Different behavior in UNIQUE and DISTINCT

From: "Mauro Delfino" <maurodelfino(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1698: Different behavior in UNIQUE and DISTINCT
Date: 2005-06-02 19:22:07
Message-ID: 20050602192207.95EE1F0AC7@svr2.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 1698
Logged by: Mauro Delfino
Email address: maurodelfino(at)gmail(dot)com
PostgreSQL version: 7.4.6 and 8.0.3
Operating system: Debian and Windows 2003 Server
Description: Different behavior in UNIQUE and DISTINCT
Details:

I have the these two tables:
CREATE TABLE table_one
( field1 VARCHAR(255) );

CREATE TABLE table_two
( field1 VARCHAR(255) UNIQUE );

table_one has 500k records. I certify that all strings are distinct with
this query:
SELECT DISTINCT field1 FROM table_one;
The query results 500k rows.

But if I try to insert the records of table_one into table_two with the
following command:
INSERT INTO table_two (field1) (SELECT field1 FROM table_one);
This error occurs:
ERROR: duplicate key violates unique constraint "table_two_field1_key"

What happened? DISTINC and UNIQUE have different algorithms to determine
when two strings are equal?

PS: I've tested this situation on PG 7.4.4 on Debian and 8.0.3 on Windows
2003 Server.
PS2: Database encoding is LATIN1

Thanks in advance.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2005-06-02 21:06:02 Re: Postgres 7.4.7 hang in async_notify
Previous Message Tom Lane 2005-06-02 18:21:25 Re: Postgres 7.4.7 hang in async_notify