Identifying Schema-Qualified Sequence References in Column Defaults - Mailing list pgsql-hackers

From jiaoshuntian@highgo.com
Subject Identifying Schema-Qualified Sequence References in Column Defaults
Date
Msg-id 166b4f59.238.19a0ee7c4bd.Coremail.jiaoshuntian@highgo.com
Whole thread Raw
Responses Re: Identifying Schema-Qualified Sequence References in Column Defaults
List 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.

pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options
Next
From: Tom Lane
Date:
Subject: Re: Identifying Schema-Qualified Sequence References in Column Defaults