From: Erik Wienhold <ewie@ewie.name>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: lukas.eder@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18660: information_schema.columns.ordinal_position has gaps when primary key columns are dropped
Date: Thu, 17 Oct 2024 17:02:35 +0200
Message-ID: <44eba52f-7991-4899-9d23-aea52522fd30@ewie.name> (raw)
In-Reply-To: <650059.1729174755@sss.pgh.pa.us>
References: <18660-9ea9b58cce21a8bb@postgresql.org>
<650059.1729174755@sss.pgh.pa.us>
On 2024-10-17 16:19 +0200, Tom Lane wrote:
> PG Bug reporting form <noreply@postgresql.org> 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?
----------
<NULL>
(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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: ewie@ewie.name, tgl@sss.pgh.pa.us, 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
In-Reply-To: <44eba52f-7991-4899-9d23-aea52522fd30@ewie.name>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox