Add the ability for the core grammar to have more than one parse target.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Jan 2021 16:03:22 +0000 (11:03 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Jan 2021 16:03:22 +0000 (11:03 -0500)
commit844fe9f159a948377907a63d0ef3fb16dc51ce50
tree5f2ac3f159f7a4795a01330044fd76049ed5bff6
parentb49154b3b7a45523ce4081fdae8d65049342fcec
Add the ability for the core grammar to have more than one parse target.

This patch essentially allows gram.y to implement a family of related
syntax trees, rather than necessarily always parsing a list of SQL
statements.  raw_parser() gains a new argument, enum RawParseMode,
to say what to do.  As proof of concept, add a mode that just parses
a TypeName without any other decoration, and use that to greatly
simplify typeStringToTypeName().

In addition, invent a new SPI entry point SPI_prepare_extended() to
allow SPI users (particularly plpgsql) to get at this new functionality.
In hopes of making this the last variant of SPI_prepare(), set up its
additional arguments as a struct rather than direct arguments, and
promise that future additions to the struct can default to zero.
SPI_prepare_cursor() and SPI_prepare_params() can perhaps go away at
some point.

Discussion: http://postgr.es/m/4165684.1607707277@sss.pgh.pa.us
14 files changed:
doc/src/sgml/spi.sgml
src/backend/commands/tablecmds.c
src/backend/executor/spi.c
src/backend/parser/gram.y
src/backend/parser/parse_coerce.c
src/backend/parser/parse_type.c
src/backend/parser/parser.c
src/backend/tcop/postgres.c
src/include/executor/spi.h
src/include/executor/spi_priv.h
src/include/parser/parser.h
src/interfaces/ecpg/preproc/parse.pl
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/pl_gram.y