From: Philip Semanchuk <philip@americanefficient.com>
To: Peter Devoy <peter@3xe.co.uk>
Cc: Psql_General (E-mail) <pgsql-general@postgresql.org>
Subject: Re: Enforcing uniqueness on [real estate/postal] addresses
Date: Mon, 11 May 2020 14:14:29 -0400
Message-ID: <F7BDBF89-E6AD-4E5B-9DCC-4D17C31CAB3D@americanefficient.com> (raw)
In-Reply-To: <CABoFc_im50V4DgcOddDiPyDWEFkVR==P26q8fBLNdgcpx--rSw@mail.gmail.com>
References: <CABoFc_im50V4DgcOddDiPyDWEFkVR==P26q8fBLNdgcpx--rSw@mail.gmail.com>
> On May 11, 2020, at 12:55 PM, Peter Devoy <peter@3xe.co.uk> wrote:
>
> 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?
Hi Peter,
I wouldn’t use empty strings in place of NULL. It’s possible to define a partial unique index that has more or less the same effect as a constraint. Have you looked into them?
Cheers
Philip
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: philip@americanefficient.com, peter@3xe.co.uk
Subject: Re: Enforcing uniqueness on [real estate/postal] addresses
In-Reply-To: <F7BDBF89-E6AD-4E5B-9DCC-4D17C31CAB3D@americanefficient.com>
References: <CABoFc_im50V4DgcOddDiPyDWEFkVR==P26q8fBLNdgcpx--rSw@mail.gmail.com> <F7BDBF89-E6AD-4E5B-9DCC-4D17C31CAB3D@americanefficient.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