From: Peter Devoy <peter@3xe.co.uk>
To: Psql_General (E-mail) <pgsql-general@postgresql.org>
Subject: Enforcing uniqueness on [real estate/postal] addresses
Date: Mon, 11 May 2020 17:55:49 +0100
Message-ID: <CABoFc_im50V4DgcOddDiPyDWEFkVR==P26q8fBLNdgcpx--rSw@mail.gmail.com> (raw)
Hi list
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
);
Of course, if any of the fields are NULL (which they often are) I end
up with duplicates.
One solution may be to add NOT NULL constraints and use empty strings
instead of NULL values but, until asking around today, I thought this was
generally considered bad practice.
Please can anyone recommend a way of approaching this? Perhaps empty strings
are pragmatic in this situation?
Kind regards
Peter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: peter@3xe.co.uk
Subject: Re: Enforcing uniqueness on [real estate/postal] addresses
In-Reply-To: <CABoFc_im50V4DgcOddDiPyDWEFkVR==P26q8fBLNdgcpx--rSw@mail.gmail.com>
References: <CABoFc_im50V4DgcOddDiPyDWEFkVR==P26q8fBLNdgcpx--rSw@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox