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 1l4Jmo-0005fe-Hp for pgsql-admin@arkaria.postgresql.org; Tue, 26 Jan 2021 08:33: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 1l4Jmn-0002nV-Fy for pgsql-admin@arkaria.postgresql.org; Tue, 26 Jan 2021 08:33:17 +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 1l4Jmn-0002nO-5M for pgsql-admin@lists.postgresql.org; Tue, 26 Jan 2021 08:33:17 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l4Jmk-0003ZW-DQ for pgsql-admin@lists.postgresql.org; Tue, 26 Jan 2021 08:33:16 +0000 Received: by mail-ej1-x62b.google.com with SMTP id gx5so21779671ejb.7 for ; Tue, 26 Jan 2021 00:33:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=ns3rnGondfMasvqUdm7t0QTpBviYN1qxCUdZTowFdB4=; b=m517JqZKvTzPby/NlykPNWOR1asjuva5sK6ebY6xkJ8Y5SpJaJVAWJgGi+dLaZ8RNU WHbDuMeD1yxt66XxHWaknteEar2NO5Q2asoBq+etrItNinAEJtcbUif2h/Qc2jsjpqKZ jJRx/dMIv01fj5RuViP9Cif9JPdxphf96hpsSobPmU71GHq75fZMCDq8CPd5hHcYYvSS D1oyypATVFxjDeu4G0Ld1O/DGLfhoZnbGlibVIFguJixL/dzjR+w4lLHk4RYAXhCreOj 1bpdb5npAGtZRty0EOI/Tzya8FnN3hhxN1UHd23NhtCEiYYccZNAT3t1Uecu2fu+itNL xxgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=ns3rnGondfMasvqUdm7t0QTpBviYN1qxCUdZTowFdB4=; b=Vez2RSiQ6fiNVN80QN3YGlTLKMD9ZeAFOMw/HBQOiCff295BqLXJN3d8KXjNNDMCsW 4g0R6yd4wrKMB5f0Ka1wvXtXcb/GsIrW6sWbAY2XjRGx5a1DPGAN5zno85oH6EvWSPOr j2fsRF5KmEpzUYsE57VEGu1IKuG21CzKttVRgU6XMlhjjii9rjXOjX438mRxoDq7gqjn a5hlYEbAk/JtVw17qAxbdJRFcqQCbYPaTLl1hFKtAsF3l3Cn8/JQ2lXPNwSr9OTmu/YO VA8OgRvBFA7gd5n8ti1WwobsN0LzDWoac9M926x4dzg2+uOsxSttnCcMUMjjVhHUWgrN 2Jew== X-Gm-Message-State: AOAM530n3Zd1bv1qdXq1yicEX+A18AKx+EiNMj6FnG9eNS+TtIPPV541 UTYeF3kpsR3vyZinPzGpRQCM3w== X-Google-Smtp-Source: ABdhPJz+kwFIH/Jjs9Z0CCjo5M0dGhSqWez5LecpC2pCQESncyXXV7CRu/nslgDzheV+h52cWESJcw== X-Received: by 2002:a17:906:6a92:: with SMTP id p18mr2641719ejr.308.1611649992584; Tue, 26 Jan 2021 00:33:12 -0800 (PST) Received: from localhost.localdomain (217-149-172-98.nat.highway.telekom.at. [217.149.172.98]) by smtp.gmail.com with ESMTPSA id u23sm5567913edt.87.2021.01.26.00.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 00:33:12 -0800 (PST) Message-ID: <5ebaba7ee42d89f8bfb2599de203612024c86e8e.camel@cybertec.at> Subject: Re: Unique constraint across all partitions? From: Laurenz Albe To: Ron , Pgsql-admin Date: Tue, 26 Jan 2021 09:33:11 +0100 In-Reply-To: References: <3d00c1f4-646c-59b7-e4dc-1d51190d2139@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 2021-01-25 at 18:09 -0600, Ron wrote: > > > > Is it possible to enforce a unique constraint across all partitions for > > > > either declarative or inheritance based partitioning? Preferably > > > > declarative based. > > > > So, yes, so long as your unique constraint takes into consideration the partitioning scheme it will enforce uniqueness across all of the partitions. But the answer to the full, but possibly > > implied, question is no. > > This is why global indices are needed. Global indexes are likely more pain than gain. They will make the best part of partitioning (attaching and detaching partitions) painfully slow. Hardly worth it to gain a tiny little bit of integrity. Within a partition, you can guarantee uniqueness easily. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com