Re: Enforcing uniqueness on [real estate/postal] addresses - Mailing list pgsql-general

From David G. Johnston
Subject Re: Enforcing uniqueness on [real estate/postal] addresses
Date
Msg-id CAKFQuwbvAGvqwb=0uj2fP-eReGt=+GKojpOCagOWnUU-0XaySA@mail.gmail.com
Whole thread Raw
In response to Enforcing uniqueness on [real estate/postal] addresses  (Peter Devoy <peter@3xe.co.uk>)
List pgsql-general
On Mon, May 11, 2020 at 9:56 AM Peter Devoy <peter@3xe.co.uk> wrote:
I need to store addresses for properties (as in real estate) so in my
naivety I created a unique constraint like this:

ALTER TABLE properties
    ADD CONSTRAINT is_unique_address
    UNIQUE (
        description, --e.g. Land north of Foo Cottage
        address_identifier_general,
        street,
        postcode
    );

 
Please can anyone recommend a way of approaching this? Perhaps empty strings
are pragmatic in this situation?

Don't add a unique table constraint (aside from an artificial primary key).

Then, if you can define a problem where you feel having a unique table constraint over the field is the correct solution - especially given the fact that you can have missing data in the relevant fields - you should post the problem and take suggestions on ways to solve it.

David J.

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Enforcing uniqueness on [real estate/postal] addresses
Next
From: Paul Jungwirth
Date:
Subject: Re: Enforcing uniqueness on [real estate/postal] addresses