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 1oQx0p-0002iL-AM for pgsql-general@arkaria.postgresql.org; Wed, 24 Aug 2022 20:30:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oQx0m-0000n3-Er for pgsql-general@arkaria.postgresql.org; Wed, 24 Aug 2022 20:30:04 +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 1oQx0m-0000mt-4L for pgsql-general@lists.postgresql.org; Wed, 24 Aug 2022 20:30:04 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oQx0i-00041X-3T for pgsql-general@lists.postgresql.org; Wed, 24 Aug 2022 20:30:01 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 689B65C0054; Wed, 24 Aug 2022 16:29:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 24 Aug 2022 16:29:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1661372999; x= 1661459399; bh=Zy4sJWoxN4CupKoJUabhc3SnPvzFJ7Bkj5xxe14Jqio=; b=c 12uzVDFv/l1bqLhWTGSBpLQ7lBc0/cXC2/fyRNYgQ9Kl5tueDd8sQK7g5fwxnT/h uSfXpqGOgzLZDFbXTaInKg15RamhA7AqtRoQQxi7Y0yIaW0WiKBv/9VsHDm00q5x nJErhjBdBPoK24fMjvqh0eNF3EkCw+Pn9D+TvzSY8pUAzjKL8A+aYsZaT0KOyvt2 WbGE2rmcmVy676zmQ/oEPwoN+MLwmxzM3EztKTPaDVxEsJqSxIv/ZpOiOpBLDfKo 4VZSKPCaRl/S/kQHNP0Wb6p/RUqDNjhnrTpFSpCH3Oj+eFWei47r8+OhjrYw+Zpk 14Cp6VAdVwrj1uJ/9VeWw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1661372999; x=1661459399; bh=Z y4sJWoxN4CupKoJUabhc3SnPvzFJ7Bkj5xxe14Jqio=; b=z7HgD4nfuWfgSaIS3 vQw3wYHdtA7od3jRIX7Y6Dd7YBPpTTTHbmRzSzxB2qdYdg+mlMTSL8L7AHbArWDB qrNqU4oQmLMepzAbFqMSUYrKCdv2L3xBZOfGEY8xpQoc0YXWnzYzsR9bQAiX797P Ne5G/gzDpEp185pYmh7cxLkh+zwXIsp0EPCMY+CsP93w+3QSdid+SNL+/y2k2EPK NLQNdUzxdihLBhX1IjpHdvYD/YOz/YyPy+BmOCQ/diD7LIbyx7OOaT9fsoJ3J6aQ AmRtoOLATvI0FOPfUlKQCFcEUXrCsQIxPdV2VNrLWylR4vuPAxTWphmOJ9AJQi1d vGuUw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdejuddgudehfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepleekgeejhfekteehfeduveetheeivdduheekudel teefvdffueehtddvgedtfeefnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrgh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughr ihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 24 Aug 2022 16:29:58 -0400 (EDT) Message-ID: <520dd935-a12c-6444-99a7-5a8f2d0f046d@aklaver.com> Date: Wed, 24 Aug 2022 13:29:57 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: Two questions about "pg_constraint" Content-Language: en-US To: Bryn Llewellyn , pgsql-general list References: <496793CE-A048-434B-ABC0-6BFC0C65C3EC@yugabyte.com> From: Adrian Klaver In-Reply-To: <496793CE-A048-434B-ABC0-6BFC0C65C3EC@yugabyte.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/24/22 13:11, Bryn Llewellyn wrote: > *Question 1: why does "pg_constraint" have a "connamespace" column?* > > I created this temporary view (using PG 14.4): > > *create temporary view all_constraints(t_owner, t_schema, t_name, > c_name, same) as > select >   r.rolname, >   s.nspname, >   c.relname, >   x.conname, >   (x.connamespace = c.relnamespace) > from >   pg_class c >   inner join >   pg_roles r >   on c.relowner = r.oid >   inner join >   pg_namespace s >   on c.relnamespace = s.oid >   inner join pg_constraint x >   on c.oid = x.conrelid > where c.relkind = 'r'; > * > > I created three tables, each with a user-created constraint. The tables > also have implicitly created primary key constraints. > > Then I did this: > > *select count(*) from all_constraints; > * > It said that the count is over a hundred. (All but the rows for my three > tables are for rows for tables in the "pg_catalog" schema.) > > Then I did this: > > *select exists(select 1 from all_constraints where not same)::text; > * > It said "false". > > Over one hundred seems to be a fair sample size. So it seems to be > reasonable to assume that "pg_constraint.connamespace = > pg_class.relnamespace" is always true. Ordinary common-sense analysis of > the query suggests this too. If the hypothesis is right, then > "connamespace" is simply a derived value. And this would be a departure > from usual table design practice. > > What do you think? > create table c1 (id integer, constraint pk1 primary key(id)); CREATE TABLE create table c2 (id integer, constraint pk1 primary key(id)); ERROR: relation "pk1" already exists create table test.c2 (id integer, constraint pk1 primary key(id)); CREATE TABLE select conname, connamespace from pg_constraint where conname = 'pk1'; conname | connamespace ---------+-------------- pk1 | 2200 pk1 | 59706 From: https://www.postgresql.org/docs/current/catalog-pg-constraint.html conname name Constraint name (not necessarily unique!) So connamespace makes it unique. -- Adrian Klaver adrian.klaver@aklaver.com