Identifying Schema-Qualified Sequence References in Column Defaults

From: jiaoshuntian(at)highgo(dot)com
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Identifying Schema-Qualified Sequence References in Column Defaults
Date: 2025-10-23 02:31:01
Message-ID: 166b4f59.238.19a0ee7c4bd.Coremail.jiaoshuntian@highgo.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

I'd like to bring attention to a metadata visibility issue when multiple schemas contain sequences with identical names, and a table column references one of them via nextval(). Currently, there appears to be no reliable way to determine which schema's sequence is actually referenced through system catalogs or views.

Repro Steps:
1、Create same-named sequences in different schemas:

SQL:
CREATE SEQUENCE public.seq_xx_yy;
CREATE SEQUENCE schema_1.seq_xx_yy;
2、Create a table with a column defaulting to nextval('seq_xx_yy'):

SQL:
CREATE TABLE schema_1.test_tab_100 (c1 int DEFAULT nextval('seq_xx_yy'));
(At creation time, search_path resolves this to public.seq_xx_yy.)

3、Query metadata:

SQL:
SELECT column_default FROM information_schema.columns
WHERE table_name = 'test_tab_100'; -- Shows: nextval('seq_xx_yy'::regclass)

Neither information_schema.columns nor pg_sequences reveals the actual schema of the referenced sequence.

Is this a known limitation?

JiaoShuntian

HighGo Inc.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-10-23 02:40:10 Re: Identifying Schema-Qualified Sequence References in Column Defaults
Previous Message Tatsuo Ishii 2025-10-23 02:06:59 Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options