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 1jYCwq-0005lZ-Ck for pgsql-general@arkaria.postgresql.org; Mon, 11 May 2020 18:14:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jYCwn-0000Ov-RK for pgsql-general@arkaria.postgresql.org; Mon, 11 May 2020 18:14:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jYCwn-0000Oo-FQ for pgsql-general@lists.postgresql.org; Mon, 11 May 2020 18:14:37 +0000 Received: from mail-qk1-x736.google.com ([2607:f8b0:4864:20::736]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jYCwk-0000Jg-Qi for pgsql-general@postgresql.org; Mon, 11 May 2020 18:14:36 +0000 Received: by mail-qk1-x736.google.com with SMTP id f189so5115129qkd.5 for ; Mon, 11 May 2020 11:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=americanefficient-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=jzXMPTeKCTjdpNjS0oMWu4WTxOJlaNXL4K8xJ6OMi8U=; b=T7wAi7Pq5ky9KQ40sSNP/OYFzxV2O9G5aPABeXVuiWXsR3i+MFBjqW2rx1wN542MBt S4aHLjcLr+fveMHUWQ6WiHQlEoF47mRZoUIrwowNE80aAtJy5uP4G6cpyiwVTw1JNUUs gXmL3lNm5SrTNUjl/9imo6uXAeNv+fnGKt07yMwtVD65EtJ8zMMZEZe+XBHCpPDe6hYS C58qxYJd2G9JoHzfri3PbSHruF2WryoNvBJJWI4Mgp4bCsB1C07S5x6XwHY4fKGT2G2c ox+8dVODRhy1y75tBDyDTVZieRH7E3+cpDjRkRvuPTnICqxc3ErwURjacDHxOtyuQovy VucQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=jzXMPTeKCTjdpNjS0oMWu4WTxOJlaNXL4K8xJ6OMi8U=; b=fgFc+PQ9jgZrhG7+t13jekaSBh+qBoFez35YrVWjxPU2dschcZQlWYVBdeG+YKdMN8 egN3eIQ0zRLHb+p6LjUZ2x3pIGO63PVzxHNW7SJ7vsLJuFIrVMLUKeNHqxH0evBoyO5w v4B6izNrTevgLOiMErVM+5cuhO0znCIKd3C1+mZLaB3KDGlNj/T4H02f/NGLjBg6WR/J HJrZt3C6283lJISqPh/+oa9M6gYQs4P5H53O1xSvltIN+dyvaa7C20lcyHAhaij6k4wl lzNIeR36s1WcquSFmrdMsLRe9T8OItHFQOl1Rcr/G/s0wInGMOqm5Ls8u+AkxAg8afvq TL0w== X-Gm-Message-State: AOAM531B3f8c5G+VOD7PpPPQIoPoVmvT1MKS8GZfA1+Idtidislx0Vbh pOBNmzvffyVe7imNNpBYBJfjOHwpRqs= X-Google-Smtp-Source: ABdhPJyeHOgIWaS3ohQ5mGqq/9sLZfemXB7Wc7jRYb4gOZ0Z8SY2bsba7zdGXpWEgetCCUxbqpKvNw== X-Received: by 2002:a37:8347:: with SMTP id f68mr89816qkd.153.1589220872563; Mon, 11 May 2020 11:14:32 -0700 (PDT) Received: from [10.0.1.5] (user-10lff1p.cable.mindspring.com. [65.87.188.57]) by smtp.gmail.com with ESMTPSA id q185sm8905004qkf.100.2020.05.11.11.14.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 May 2020 11:14:31 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: Enforcing uniqueness on [real estate/postal] addresses From: Philip Semanchuk In-Reply-To: Date: Mon, 11 May 2020 14:14:29 -0400 Cc: "Psql_General (E-mail)" Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Peter Devoy X-Mailer: Apple Mail (2.3608.80.23.2.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On May 11, 2020, at 12:55 PM, Peter Devoy wrote: >=20 > Hi list >=20 > I need to store addresses for properties (as in real estate) so in my > naivety I created a unique constraint like this: >=20 > ALTER TABLE properties > ADD CONSTRAINT is_unique_address > UNIQUE ( > description, --e.g. Land north of Foo Cottage > address_identifier_general, > street, > postcode > ); >=20 > Of course, if any of the fields are NULL (which they often are) I end > up with duplicates. >=20 > 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. >=20 > Please can anyone recommend a way of approaching this? Perhaps empty = strings > are pragmatic in this situation? Hi Peter, I wouldn=E2=80=99t use empty strings in place of NULL. It=E2=80=99s = possible to define a partial unique index that has more or less the same = effect as a constraint. Have you looked into them?=20 Cheers Philip