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 1t1S1a-00GN5z-4w for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Oct 2024 15:02:50 +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 1t1S1X-0060CF-F1 for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Oct 2024 15:02:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t1S1W-0060Bx-SO for pgsql-bugs@lists.postgresql.org; Thu, 17 Oct 2024 15:02:47 +0000 Received: from mout-u-204.mailbox.org ([2001:67c:2050:101:465::204]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t1S1U-001Ymy-Tu for pgsql-bugs@lists.postgresql.org; Thu, 17 Oct 2024 15:02:46 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4XTrfk1d2Hz9tVM; Thu, 17 Oct 2024 17:02:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ewie.name; s=MBO0001; t=1729177358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=N2RjOXkKPhzby/Dy+sLMPQpZod0siRI3P4UK9lQdLbc=; b=z/s+Gn3ddTS4xY6biBhA6Uri25wKXNBwsvisaKp553QHrqkLhMNHJRJZAxNUZgIM47Lo11 /5NY/5EUWfOXErQKDJeqtUytkBbauHpFYAR1hpNJr4QPIGfugihAW7GAlwwaG3HnQ87s6j w7AfTbWSi1uAk+33zz6u0XTPeHyqcmDXOVAb2jvRX768jEw/W3+wf6c9JnrfpUsK0ugXOf Y7qEiKyv3ROiCISlQ+BKdcR5y7cZeXM9a9xQv7getrLwP57T0ReJzSDeFKQ/mlAbnbNEEh dNVgT5jTZp5tdPPhXkAXJ6yoZvI8hRQVFBSprBAUssczwNZsaFAaPCeI6alJvQ== Date: Thu, 17 Oct 2024 17:02:35 +0200 From: Erik Wienhold To: Tom Lane Cc: lukas.eder@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18660: information_schema.columns.ordinal_position has gaps when primary key columns are dropped Message-ID: <44eba52f-7991-4899-9d23-aea52522fd30@ewie.name> References: <18660-9ea9b58cce21a8bb@postgresql.org> <650059.1729174755@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <650059.1729174755@sss.pgh.pa.us> X-Rspamd-Queue-Id: 4XTrfk1d2Hz9tVM List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-10-17 16:19 +0200, Tom Lane wrote: > PG Bug reporting form writes: > > [ information_schema.columns.ordinal_position is just a copy of attnum ] > > > This is against the SQL standard specification of the > > information_schema.columns.ordinal_position column, which has a constraint > > as follows: > > > CONSTRAINT COLUMNS_ORDINAL_POSITION_CONTIGUOUS_CHECK CHECK (0 = ALL ( > > SELECT MAX(ORDINAL_POSITION) - COUNT(*) > > FROM COLUMNS > > GROUP BY > > TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME > > )) Same for information_schema.attributes.ordinal_position, although I don't know if that defines an equivalent constraint. > Hm. I'm not sure if it's worth making that view even slower in order > to clean up the numbering. But then we should at least fix the docs which say that the count starts at 1. > Just as an aside, we'd still be violating the letter of this > constraint, because for a zero-column table the sub-select will > produce NULL not 0. I don't think so. That sub-select only returns NULL when looking up that empty table. That entire CHECK expression with "ALL" will happily return true. regress=# create table t0 (); CREATE TABLE regress=# select max(ordinal_position) - count(*) from information_schema.columns where table_name = 't0'; ?column? ---------- (1 row) regress=# select 0 = all (select max(ordinal_position) - count(*) from information_schema.columns group by table_catalog, table_schema, table_name); ?column? ---------- t (1 row) -- Erik