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

From Philip Semanchuk
Subject Re: Enforcing uniqueness on [real estate/postal] addresses
Date
Msg-id F7BDBF89-E6AD-4E5B-9DCC-4D17C31CAB3D@americanefficient.com
Whole thread Raw
In response to Enforcing uniqueness on [real estate/postal] addresses  (Peter Devoy <peter@3xe.co.uk>)
List pgsql-general

> 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
sameeffect as a constraint. Have you looked into them?  

Cheers
Philip








pgsql-general by date:

Previous
From: Peter Devoy
Date:
Subject: Enforcing uniqueness on [real estate/postal] addresses
Next
From: Matthias Apitz
Date:
Subject: Re: PostgreSQL client hangs sometimes on 'EXEC SQL PREPAREsid_sisisinst FROM :select_anw;'