Re: Enforcing uniqueness on [real estate/postal] addresses

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Peter Devoy <peter(at)3xe(dot)co(dot)uk>
Cc: "Psql_General (E-mail)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Enforcing uniqueness on [real estate/postal] addresses
Date: 2020-05-11 18:33:11
Message-ID: CAKFQuwbvAGvqwb=0uj2fP-eReGt=+GKojpOCagOWnUU-0XaySA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, May 11, 2020 at 9:56 AM Peter Devoy <peter(at)3xe(dot)co(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paul Jungwirth 2020-05-11 18:33:45 Re: Enforcing uniqueness on [real estate/postal] addresses
Previous Message Adrian Klaver 2020-05-11 18:32:46 Re: Enforcing uniqueness on [real estate/postal] addresses