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 1jYBj0-00034h-EN for pgsql-general@arkaria.postgresql.org; Mon, 11 May 2020 16:56:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jYBiy-0003pk-GU for pgsql-general@arkaria.postgresql.org; Mon, 11 May 2020 16:56:16 +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 1jYBiy-0003pc-3T for pgsql-general@lists.postgresql.org; Mon, 11 May 2020 16:56:16 +0000 Received: from mail-qv1-xf2c.google.com ([2607:f8b0:4864:20::f2c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jYBiq-00082A-TG for pgsql-general@postgresql.org; Mon, 11 May 2020 16:56:15 +0000 Received: by mail-qv1-xf2c.google.com with SMTP id di6so4825976qvb.10 for ; Mon, 11 May 2020 09:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3xe-co-uk.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=Dz1McDLulr3qxf5dhDlM3M89LDz3+kdna0XxNreE3YU=; b=h4BQ/N0LkXPRFj0rsImtdSn3LPZTqi/fRemxXjTT4UrxX0QGTz0h/1aJYmRN4s0kjG tvc/ODkaVWqNI1xwQbxi2tu30/Xb+WUV4m2928hZjAnUrMVVCQYKayZuV91wcJjnBMPG T2vuBcp9uG476uo4loybAnyGwOSIdIg0JxzDuVMu/GGhiY4V1ORAy6JPGoRbK2NdqkcB 2voHEDNFZu/Br0+AJrU02I4sZ31xiLPRnQxLJyjuRTHXJD2lP4vlq2O/izeYxoSpaNQ8 ZpmzKw7PfONOBBJHf37/HLzipL0JkLVEm0hF9VLV4y+wcHO5sZPe7rO+RwTnMugW9Yis m43A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Dz1McDLulr3qxf5dhDlM3M89LDz3+kdna0XxNreE3YU=; b=hfw0f0XgJ5jaJa/W5/ZxatAjqK57vS7H6Yb2BvjX2ipD4yTXKlTgdS58RPrXs8YlXn jzTkl4y6apwFDTtsuLVyYOBuJtJTcVFhzJs0hp8CkMimUplZEIfHGmpdOtud2lNdqMiL NlVO8zA5kkf7y550sS1VH5moZFsbA441eS33/Td7nGhbTudMhnaaTOpnpS3rLJGzZfiR B4vGNWKTjH6jTJzm/q9lq91v2zu+lBW4pYYwyRblP7XVW7ipY+FTMBEvlNq6eUGGnGWb E0ZAcS35kT1/aOUmIRmsju9Nwibqktk6mk7pLyCrQSs1upKU8FEehMK0biPLdh59J6B2 N6HA== X-Gm-Message-State: AGi0PuZE7UoADV2L4gcWBv3ERb5vR7P3oH3H+g5oihbXWKtBvxxx2uyO OCD9mgaCVuWd2N80BhfX0BRcLwi9K90n66wocXm+fQjXXA== X-Google-Smtp-Source: APiQypKWnJ6CX2hwAs9A3ycrfkyaSsRHP6M6bTjhnxUpgyi4f1GRhj6vrjX82H3byZv/+kavpDt6uNMCCIFCLoIsVDM= X-Received: by 2002:a0c:f212:: with SMTP id h18mr12710239qvk.203.1589216165873; Mon, 11 May 2020 09:56:05 -0700 (PDT) MIME-Version: 1.0 From: Peter Devoy Date: Mon, 11 May 2020 17:55:49 +0100 Message-ID: Subject: Enforcing uniqueness on [real estate/postal] addresses To: "Psql_General (E-mail)" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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