question about unique indexes - Mailing list pgsql-general

From Jonathan Vanasco
Subject question about unique indexes
Date
Msg-id 10AF69BB-A35C-4784-8502-319A4E3CACF1@2xlp.com
Whole thread Raw
Responses Re: question about unique indexes
Re: question about unique indexes
Re: question about unique indexes
List pgsql-general
-- running pg 8.4

i have a table defining geographic locations

    id
    lat
    long
    country_id not null
    state_id
    city_id
    postal_code_id

i was given a unique index on
    (country_id, state_id, city_id, postal_code_id)

the unique index isn't working as i'd expect it to.  i was hoping
someone could explain why:

in the two records below, only country_id and state_id are assigned
( aside from the serial )

geographic_location_id | coordinates_latitude | coordinates_longitude
| country_id | state_id | city_id | postal_code_id
------------------------+----------------------+-----------------------
+------------+----------+---------+----------------
                     312 |
|                       |        233 |       65 |         |
                     443 |
|                       |        233 |       65 |         |

i was under the expectation that the unique constraint would apply in
this place.

from the docs:
    When an index is declared unique, multiple table rows with equal
indexed values are not allowed. Null values are not considered equal.
A multicolumn unique index will only reject cases where all indexed
columns are equal in multiple rows.


pgsql-general by date:

Previous
From: Christoph Zwerschke
Date:
Subject: Finding rows with text columns beginning with other text columns
Next
From: pgsql
Date:
Subject: Re: Please help me debug regular segfaults on 8.3.10