diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-01-04 11:03:22 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-01-04 11:03:22 -0500 |
commit | 844fe9f159a948377907a63d0ef3fb16dc51ce50 (patch) | |
tree | 5f2ac3f159f7a4795a01330044fd76049ed5bff6 /doc/src | |
parent | b49154b3b7a45523ce4081fdae8d65049342fcec (diff) | |
download | postgresql-844fe9f159a948377907a63d0ef3fb16dc51ce50.tar.gz postgresql-844fe9f159a948377907a63d0ef3fb16dc51ce50.zip |
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 'doc/src')
-rw-r--r-- | doc/src/sgml/spi.sgml | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/doc/src/sgml/spi.sgml b/doc/src/sgml/spi.sgml index 6e92e15ca3b..f5e0a35da06 100644 --- a/doc/src/sgml/spi.sgml +++ b/doc/src/sgml/spi.sgml @@ -1105,6 +1105,11 @@ SPIPlanPtr SPI_prepare_cursor(const char * <parameter>command</parameter>, int < for the <structfield>options</structfield> field of <structname>DeclareCursorStmt</structname>. <function>SPI_prepare</function> always takes the cursor options as zero. </para> + + <para> + This function is now deprecated in favor + of <function>SPI_prepare_extended</function>. + </para> </refsect1> <refsect1> @@ -1176,6 +1181,122 @@ SPIPlanPtr SPI_prepare_cursor(const char * <parameter>command</parameter>, int < <!-- *********************************************** --> +<refentry id="spi-spi-prepare-extended"> + <indexterm><primary>SPI_prepare_extended</primary></indexterm> + + <refmeta> + <refentrytitle>SPI_prepare_extended</refentrytitle> + <manvolnum>3</manvolnum> + </refmeta> + + <refnamediv> + <refname>SPI_prepare_extended</refname> + <refpurpose>prepare a statement, without executing it yet</refpurpose> + </refnamediv> + + <refsynopsisdiv> +<synopsis> +SPIPlanPtr SPI_prepare_extended(const char * <parameter>command</parameter>, + const SPIPrepareOptions * <parameter>options</parameter>) +</synopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + + <para> + <function>SPI_prepare_extended</function> creates and returns a prepared + statement for the specified command, but doesn't execute the command. + This function is equivalent to <function>SPI_prepare</function>, + with the addition that the caller can specify options to control + the parsing of external parameter references, as well as other facets + of query parsing and planning. + </para> + </refsect1> + + <refsect1> + <title>Arguments</title> + + <variablelist> + <varlistentry> + <term><literal>const char * <parameter>command</parameter></literal></term> + <listitem> + <para> + command string + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><literal>const SPIPrepareOptions * <parameter>options</parameter></literal></term> + <listitem> + <para> + struct containing optional arguments + </para> + </listitem> + </varlistentry> + </variablelist> + + <para> + Callers should always zero out the entire <parameter>options</parameter> + struct, then fill whichever fields they want to set. This ensures forward + compatibility of code, since any fields that are added to the struct in + future will be defined to behave backwards-compatibly if they are zero. + The currently available <parameter>options</parameter> fields are: + </para> + + <variablelist> + <varlistentry> + <term><literal>ParserSetupHook <parameter>parserSetup</parameter></literal></term> + <listitem> + <para> + Parser hook setup function + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><literal>void * <parameter>parserSetupArg</parameter></literal></term> + <listitem> + <para> + pass-through argument for <parameter>parserSetup</parameter> + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><literal>RawParseMode <parameter>parseMode</parameter></literal></term> + <listitem> + <para> + mode for raw parsing; <literal>RAW_PARSE_DEFAULT</literal> (zero) + produces default behavior + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><literal>int <parameter>cursorOptions</parameter></literal></term> + <listitem> + <para> + integer bit mask of cursor options; zero produces default behavior + </para> + </listitem> + </varlistentry> + </variablelist> + </refsect1> + + <refsect1> + <title>Return Value</title> + + <para> + <function>SPI_prepare_extended</function> has the same return conventions as + <function>SPI_prepare</function>. + </para> + </refsect1> +</refentry> + +<!-- *********************************************** --> + <refentry id="spi-spi-prepare-params"> <indexterm><primary>SPI_prepare_params</primary></indexterm> @@ -1208,6 +1329,11 @@ SPIPlanPtr SPI_prepare_params(const char * <parameter>command</parameter>, with the addition that the caller can specify parser hook functions to control the parsing of external parameter references. </para> + + <para> + This function is now deprecated in favor + of <function>SPI_prepare_extended</function>. + </para> </refsect1> <refsect1> |