Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tsOWD-001Uis-BY for pgsql-general@arkaria.postgresql.org; Wed, 12 Mar 2025 16:01:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tsOWB-0082Ra-UR for pgsql-general@arkaria.postgresql.org; Wed, 12 Mar 2025 16:01:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tsOWB-0082R0-Jh for pgsql-general@lists.postgresql.org; Wed, 12 Mar 2025 16:01:15 +0000 Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tsOW8-002S8d-2W for pgsql-general@postgresql.org; Wed, 12 Mar 2025 16:01:13 +0000 Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.stl.internal (Postfix) with ESMTP id 47FB52540143; Wed, 12 Mar 2025 12:01:12 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Wed, 12 Mar 2025 12:01:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1741795272; x=1741881672; bh=F9UPFCWpMjHPi2uz4VMCkBR8jY9OIbqe6X2MouwAcis=; b= eM8m4n+iCCASEXno5c0xTnKhjiaOthdQlfNSaYDpfFx4pWLvc7W652QaQkl7S1+5 cYTLtT2Nm8Ep94hE5jEeU4HLZbcdG4bAbJf5UPUyxtBmUZ1wUNaSJ9nGW28XI2a6 PK/+4t1Rn8CBtUtv0GEAfy4dIsEJxNMAFNyeng37Z2w/Z5BJUUWzvxxAolloj/29 hyT+WUQT83DNWiHT2gQsf9OKqrcg5thfqTERp6eIS52VP7OGn/52B9q48EzQsZK/ V04SzVUK5aYdW/3yb4YxxqjFoQELsLD7pn+ChUI83uxvdFRQna/makBPnE44xGvM kbraoyzS5GiuULVaTwrFcw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1741795272; x= 1741881672; bh=F9UPFCWpMjHPi2uz4VMCkBR8jY9OIbqe6X2MouwAcis=; b=t Cf3A+vQ79gz/7LI96JQGd4EvjV3AIfzIfKuM9kR/GZpDlWMbeWld5HIjkVAGb61U iEFqCR744fMW4kIhdjlp5MNZoeOtfWdxM+BfBIvXR2o8oK1fOzQZC/9+yAf7EZIZ MyGiWFhtsGzak3w6wrTwmEySbDBJFSCVKlV8pw9meWeWtgqvfX0RF3nEZC1Vftcu AeGF6hgcoqrUiwXRdxrzrM2sGqa42E/UgtoPBPqK3gP9UOeiU5PTlIq1q4yXJQMy rqw94rnACfdzVq/8FAC0csXyK1rPmZ6XqzpCLmuyiv47/Vl16CTl2YYf2sOqtCcR MoslVvaILSI5FYpPftEaw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduvdehgeelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkff ggfgfuhffvvehfjggtgfesthekredttddvjeenucfhrhhomheptegurhhirghnucfmlhgr vhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtf frrghtthgvrhhnpedvieefffefgfeftdfgjeetteduvdekieevieffgfdvkeevieehfedu vedvjeffffenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmh htphhouhhtpdhrtghpthhtohepmhgrrhhksghrrgguhihjuhesohhuthhlohhokhdrtgho mhdprhgtphhtthhopehpghhsqhhlqdhgvghnvghrrghlsehpohhsthhgrhgvshhqlhdroh hrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Mar 2025 12:01:11 -0400 (EDT) Message-ID: <08c96195-3d5f-4902-b5d7-15916a02e23f@aklaver.com> Date: Wed, 12 Mar 2025 09:01:10 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Duplicate Key Values From: Adrian Klaver To: mark bradley Cc: pgsql-general References: <9d919848-3fe1-46fd-b343-c5f2931864f7@aklaver.com> <513ddbee-135c-4af2-b6f6-acca667b8d09@aklaver.com> <84aac7bf-5638-4f1f-9772-ace0ea27e848@aklaver.com> <9203d0df-0ddd-4564-a985-59bcfcf1d294@aklaver.com> Content-Language: en-US In-Reply-To: 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 3/12/25 08:46, Adrian Klaver wrote: > On 3/11/25 13:24, Adrian Klaver wrote: >> On 3/11/25 12:55, mark bradley wrote: >>> It happened again.  Now there are no sequences (although there once >>> was). >> >> Read my previous post and provide the information requested. >> > > Mark sent me the below, which answers some of the questions, namely > there is inheritance going on: Mark, to illustrate: create table node (node_id integer primary key, fld1 varchar); create table node_1 (node_id integer primary key, node_1_fld boolean) inherits ( node); NOTICE: merging column "node_id" with inherited definition insert into node values (1, 'dog'); insert into node_1 values (1, 'cat', 'f'); select * from node; node_id | fld1 ---------+------ 1 | dog 1 | cat This is explained here: https://www.postgresql.org/docs/current/sql-createtable.html INHERITS ( parent_table [, ... ] ) "... , and by default the data of the child table is included in scans of the parent(s)." This explains why you see duplicates of node_id. Though if you try to enter a duplicate value in to a particular table you get: insert into node_1 values (1, 'test', 't'); ERROR: duplicate key value violates unique constraint "node_1_pkey" DETAIL: Key (node_id)=(1) already exists. This still does not explain why REINDEX TABLE node; caused data to disappear? > > Did you ever run VALIDATE CONSTRAINT against them? > Here is the run As error notes VALIDATE CONSTRAINT only works on FK and check constraints. You would need to run against the FK constraints that where marked NOT VALID e.g "dataset" on the dataset table. Honestly, I think you need rework your data model. Not sure what the inheritance is getting you. Seems simpler to just have the node table not be inherited and just use FK relationships back to it. > > Universal Metadata Schema=# ALTER TABLE node VALID > ATE CONSTRAINT node_id; > ERROR: constraint "node_id" of relation "node" is > not a foreign key or check constraint > Universal Metadata Schema=# > > Universal Metadata Schema=# ALTER TABLE dataset VA > LIDATE CONSTRAINT node_id; > ALTER TABLE > Universal Metadata Schema=# > > > > > -- Adrian Klaver adrian.klaver@aklaver.com