Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZtdJ-0001e9-76 for pgsql-general@arkaria.postgresql.org; Sat, 16 May 2020 10:01:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZtdH-0000YS-5i for pgsql-general@arkaria.postgresql.org; Sat, 16 May 2020 10:01:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZtdG-0000WR-SS for pgsql-general@lists.postgresql.org; Sat, 16 May 2020 10:01:26 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZtd7-00076g-5b for pgsql-general@lists.postgresql.org; Sat, 16 May 2020 10:01:25 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id C5E28308B; Sat, 16 May 2020 12:01:11 +0200 (CEST) Date: Sat, 16 May 2020 12:01:11 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Enforcing uniqueness on [real estate/postal] addresses Message-ID: <20200516100111.GA8152@hjp.at> References: <87o8qu0ygd.fsf@gmail.com> <20200512170741.GA11324@hjp.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mP3DRpeJDSE+ciuQ" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-05-12 21:55:56 +0100, Peter Devoy wrote: > >Is is possible to have two entries which have the same > >address_identifier_general, street and postcode, but different > >descriptions? >=20 > Unfortunately, yes. The data comes from gov't systems to > regulate the development/alteration of arbitrary pieces of property and > those pieces do not always have a postal address. E.g. a farmer may > one year apply to erect a wind turbine in "field north of Foo Cottage" > and the next year apply to demolish "barnhouse west of Foo Cottage". I see. So postcode, street, address_identifier_general, description (from least to most specific) together identify an object. Going back to your original question I think that in this case it is actually useful to distinguish between NULL (unknown) and '' (empty), and if unknown values are forbidden, enforce that with a non null constraint. Consider the following examples: postcode | street | address_identifier_general | description 1234 | main street | 12 | '' 1234 | main street | 12 | NULL 1234 | main street | NULL | bike shed 2345 | '' | 12 | '' The first one refers to the whole property at main street 12. The second one maybe only to a part of it but we don't know which one.=20 In the third example tghe address_identifier_general is unknown. Some bike shed on main street, There might be more than one, so PostgreSQL is correct not to enforce the unique constraint. In the last one there is no street name - it's not unknown, we know that there is none because this is a small village which doesn't have street names, just house numbers. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --mP3DRpeJDSE+ciuQ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl6/ueMACgkQ8g5IURL+ KF0CIhAAqRUps2d9h3v2QZDlVMGzfdgOcu0So6LygY+k/Exrg++dewo/m2nWvBJN AZhEAwnl7AQpsRZoNr3lohY0y+8k+hpcHt2UPB5vP5jn9D3wfSBfpR0stmiKdu/c RHrwkPQyXE8TYS34HfKgk0Xnj+mFpLFctrzwFJ2fdJrSxA6pS0Kr/IWhsgAn39BE gAMhsnVl/oBj7A5twMKkYLAbxo/7JcegCMBFHsStuI3W3Eryw/O+6UE6n6n5dCWb htf6JRUd3geRHrOZC31yT51FLOAxkHhCtS3uISwdBfed1eUQ8dJyLHTtZ6ioTIYx vN86qQ6Kn5rTEksGFlTssqYstYcfghz63ZsJJGjnBPJIlFuWb3pDUOypOmZhl49g 3mlBIkdJTx4E1awqvhrIpe1Vxw75peEfGyVypvmiXYe2wTBVC38Thnqyn3UvxN7Z Me9xLLDPgu2TppO0Wd2jBUtUlD/Zyk16eBy2Tqr3Ve5WlDqLRQuvLD12wqot6Cd8 FmxGiUsRuoqIalStCpmi1vJYcgSuJ3hLNT1tltQFc/IgJgwsc+skbjdhCswspBQW wKmepr60xhaGpkZwU6vIApWQCa+4KWg8QHC9IHXW7OLh552hfUNrklBckrDDwA/6 ewTCqdeNddKROSn4rNxp22t9x8azXqXYGIfk3nil6AVgg0OktYQ= =fMT3 -----END PGP SIGNATURE----- --mP3DRpeJDSE+ciuQ--