postgresql/src/fe_utils
Tom Lane 049b742daa psql: Tighten heuristics for BEGIN/END within CREATE SCHEMA.
Since d51697484, psql's scanner treats CREATE SCHEMA as a command that
may contain SQL-standard routine bodies, so that semicolons inside
BEGIN ATOMIC ... END blocks do not terminate the command too early.
However, the code counted BEGIN/END throughout CREATE SCHEMA, so that
it could be fooled by valid (and previously accepted) code such as

    CREATE SCHEMA s CREATE VIEW begin AS SELECT 1;

Improve this by explicitly checking whether each CREATE sub-clause is
CREATE [OR REPLACE] {FUNCTION|PROCEDURE}, and only counting BEGIN/END
within those clauses.  Since CREATE FUNCTION/PROCEDURE wasn't allowed
in CREATE SCHEMA before d51697484, this will not risk failure on any
cases that worked before v19.

There remain cases that fool the top-level CREATE FUNCTION/PROCEDURE
heuristic and thus also the CREATE SCHEMA case, for example

    CREATE FUNCTION begin () ...

But that's been true all along with no field complaints, so we'll
leave that issue for another day.

In the name of keeping things readable, move the logic supporting
this out of the {identifier} flex rule and into some small new
subroutines.  Also rename existing related PsqlScanState fields
to help distinguish them from the added fields.

This patch also fixes what seems to me (tgl) a small bug: \;
would reset BEGIN/END detection even when inside parens or BEGIN.
That's unlike what a plain semicolon would do, and no such effect
is suggested by the documentation.

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/8E03BB8D-003D-4850-9772-5F8015A5A0C7@gmail.com
2026-06-23 14:12:03 -04:00
..
.gitignore Move psql's psqlscan.l into src/fe_utils. 2016-03-24 20:28:47 -04:00
archive.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
astreamer_file.c Prevent path traversal in pg_basebackup and pg_rewind 2026-05-11 05:13:47 -07:00
astreamer_gzip.c Fix multiple bugs in astreamer pipeline code. 2026-03-29 09:01:47 -04:00
astreamer_lz4.c Fix poorly-sized buffers in astreamer compression modules. 2026-03-24 12:17:12 -04:00
astreamer_tar.c Prevent path traversal in pg_basebackup and pg_rewind 2026-05-11 05:13:47 -07:00
astreamer_zstd.c Fix poorly-sized buffers in astreamer compression modules. 2026-03-24 12:17:12 -04:00
cancel.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
conditional.c fe_utils: Sprinkle some pg_malloc_object() and pg_malloc_array() 2026-02-24 12:34:42 +09:00
connect_utils.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
Makefile Update copyright for 2026 2026-01-01 13:24:10 -05:00
mbprint.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
meson.build meson: allow disabling building/installation of static libraries. 2026-02-23 16:45:40 +01:00
option_utils.c Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
parallel_slot.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
print.c psql: Fix expanded aligned output 2026-06-08 14:37:51 +09:00
psqlscan.l psql: Tighten heuristics for BEGIN/END within CREATE SCHEMA. 2026-06-23 14:12:03 -04:00
query_utils.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
recovery_gen.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
simple_list.c fe_utils: Sprinkle some pg_malloc_object() and pg_malloc_array() 2026-02-24 12:34:42 +09:00
string_utils.c Disallow CR and LF in database, role, and tablespace names 2026-02-23 11:19:13 -05:00
version.c Update copyright for 2026 2026-01-01 13:24:10 -05:00