diff options
| author | Tom Lane | 2021-01-04 16:03:22 +0000 |
|---|---|---|
| committer | Tom Lane | 2021-01-04 16:03:22 +0000 |
| commit | 844fe9f159a948377907a63d0ef3fb16dc51ce50 (patch) | |
| tree | 5f2ac3f159f7a4795a01330044fd76049ed5bff6 /src/include | |
| parent | b49154b3b7a45523ce4081fdae8d65049342fcec (diff) | |
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: https://postgr.es/m/4165684.1607707277@sss.pgh.pa.us
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/executor/spi.h | 13 | ||||
| -rw-r--r-- | src/include/executor/spi_priv.h | 1 | ||||
| -rw-r--r-- | src/include/parser/parser.h | 20 |
3 files changed, 32 insertions, 2 deletions
diff --git a/src/include/executor/spi.h b/src/include/executor/spi.h index 6e603d007d7..9c70603434a 100644 --- a/src/include/executor/spi.h +++ b/src/include/executor/spi.h @@ -15,7 +15,7 @@ #include "commands/trigger.h" #include "lib/ilist.h" -#include "nodes/parsenodes.h" +#include "parser/parser.h" #include "utils/portal.h" @@ -33,6 +33,15 @@ typedef struct SPITupleTable SubTransactionId subid; /* subxact in which tuptable was created */ } SPITupleTable; +/* Optional arguments for SPI_prepare_extended */ +typedef struct SPIPrepareOptions +{ + ParserSetupHook parserSetup; + void *parserSetupArg; + RawParseMode parseMode; + int cursorOptions; +} SPIPrepareOptions; + /* Plans are opaque structs for standard users of SPI */ typedef struct _SPI_plan *SPIPlanPtr; @@ -113,6 +122,8 @@ extern int SPI_execute_with_receiver(const char *src, extern SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes); extern SPIPlanPtr SPI_prepare_cursor(const char *src, int nargs, Oid *argtypes, int cursorOptions); +extern SPIPlanPtr SPI_prepare_extended(const char *src, + const SPIPrepareOptions *options); extern SPIPlanPtr SPI_prepare_params(const char *src, ParserSetupHook parserSetup, void *parserSetupArg, diff --git a/src/include/executor/spi_priv.h b/src/include/executor/spi_priv.h index 29a77781a9d..ce0f58ce687 100644 --- a/src/include/executor/spi_priv.h +++ b/src/include/executor/spi_priv.h @@ -95,6 +95,7 @@ typedef struct _SPI_plan bool no_snapshots; /* let the caller handle the snapshots */ List *plancache_list; /* one CachedPlanSource per parsetree */ MemoryContext plancxt; /* Context containing _SPI_plan and data */ + RawParseMode parse_mode; /* raw_parser() mode */ int cursor_options; /* Cursor options used for planning */ int nargs; /* number of plan arguments */ Oid *argtypes; /* Argument types (NULL if nargs is 0) */ diff --git a/src/include/parser/parser.h b/src/include/parser/parser.h index 09730030444..80d90027cc4 100644 --- a/src/include/parser/parser.h +++ b/src/include/parser/parser.h @@ -18,6 +18,24 @@ #include "nodes/parsenodes.h" +/* + * RawParseMode determines the form of the string that raw_parser() accepts: + * + * RAW_PARSE_DEFAULT: parse a semicolon-separated list of SQL commands, + * and return a List of RawStmt nodes. + * + * RAW_PARSE_TYPE_NAME: parse a type name, and return a one-element List + * containing a TypeName node. + * + * ... more to come ... + */ +typedef enum +{ + RAW_PARSE_DEFAULT = 0, + RAW_PARSE_TYPE_NAME +} RawParseMode; + +/* Values for the backslash_quote GUC */ typedef enum { BACKSLASH_QUOTE_OFF, @@ -32,7 +50,7 @@ extern PGDLLIMPORT bool standard_conforming_strings; /* Primary entry point for the raw parsing functions */ -extern List *raw_parser(const char *str); +extern List *raw_parser(const char *str, RawParseMode mode); /* Utility functions exported by gram.y (perhaps these should be elsewhere) */ extern List *SystemFuncName(char *name); |
