Re: psql: Fix CREATE SCHEMA scanning of nested routine bodies

Chao Li <li.evan.chao@gmail.com>

From: Chao Li <li.evan.chao@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Postgres hackers <pgsql-hackers@lists.postgresql.org>, Kirill Reshke <reshkekirill@gmail.com>, jian he <jian.universality@gmail.com>
Date: 2026-06-24T00:49:23Z
Lists: pgsql-hackers

> On Jun 24, 2026, at 02:16, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
> Chao Li <li.evan.chao@gmail.com> writes:
>> Following your suggestion, I moved the "{identifier}" logic into a new helper psqlscan_track_identifier(), and added “create_schema_identifiers" to PsqlScanStateData to track identifiers from the current top-level CREATE element within CREATE SCHEMA in the same way as the top level “identifiers". I also added a few more test cases.
> 
>> Please see the attached v2 for details.
> 
> Pushed with some mostly-cosmetic changes.

Thanks for pushing.

> Notably, I renamed the
> existing "identifiers" field to help distinguish it from the new one.
> 

The renaming makes sense.

> I didn't use your test cases because it seemed unduly expensive to do
> it that way.  We can perfectly well exercise this as part of plain-SQL
> regression testing, so I just added a booby-trap case in
> create_schema.sql Without this fix, psql marches on and tries to run
> the various \d commands after the CREATE SCHEMA before it's sent the
> CREATE SCHEMA command.  So even though no error is reported, the
> output is quite different.
> 

I think I over worried about the test. Thank for simplifying the tests.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/







Commits

  1. psql: Tighten heuristics for BEGIN/END within CREATE SCHEMA.

  2. Execute foreign key constraints in CREATE SCHEMA at the end.