<listitem>
<para>
Allows for mapping between system and database user names. See
- <xref linkend="auth-username-maps"/> for details. For a SSPI/Kerberos
+ <xref linkend="auth-username-maps"/> for details. For an SSPI/Kerberos
principal, such as <literal>username@EXAMPLE.COM</literal> (or, less
commonly, <literal>username/hostbased@EXAMPLE.COM</literal>), the
user name used for mapping is
In general, enclose the value in single quotes, doubling any single
quotes within the value. Quotes can usually be omitted if the value
is a simple number or identifier, however.
- (Values that match a SQL keyword require quoting in some contexts.)
+ (Values that match an SQL keyword require quoting in some contexts.)
</para>
</listitem>
<productname>PostgreSQL</productname> provides three SQL
commands to establish configuration defaults.
The already-mentioned <command>ALTER SYSTEM</command> command
- provides a SQL-accessible means of changing global defaults; it is
+ provides an SQL-accessible means of changing global defaults; it is
functionally equivalent to editing <filename>postgresql.conf</filename>.
In addition, there are two commands that allow setting of defaults
on a per-database or per-role basis:
<literal>\'</literal>. However, use of <literal>\'</literal> creates security risks
because in some client character set encodings, there are multibyte
characters in which the last byte is numerically equivalent to ASCII
- <literal>\</literal>. If client-side code does escaping incorrectly then a
+ <literal>\</literal>. If client-side code does escaping incorrectly then an
SQL-injection attack is possible. This risk can be prevented by
making the server reject queries in which a quote mark appears to be
escaped by a backslash.
<para>
The reason that single quotes must be doubled, as shown
in <xref linkend="datatype-binary-sqlesc"/>, is that this
- is true for any string literal in a SQL command. The generic
+ is true for any string literal in an SQL command. The generic
string-literal parser consumes the outermost single quotes
and reduces any pair of single quotes to one data character.
What the <type>bytea</type> input function sees is just one
<title>Return Value</title>
<para>
- For an async query (that is, a SQL statement returning rows),
+ For an async query (that is, an SQL statement returning rows),
the function returns the row(s) produced by the query. To use this
function, you will need to specify the expected set of columns,
as previously discussed for <function>dblink</function>.
</para>
<para>
- For an async command (that is, a SQL statement not returning rows),
+ For an async command (that is, an SQL statement not returning rows),
the function returns a single row with a single text column containing
the command's status string. It is still necessary to specify that
the result will have a single text column in the calling <literal>FROM</literal>
<para>
<function>dblink_build_sql_insert</function> can be useful in doing selective
replication of a local table to a remote database. It selects a row
- from the local table based on primary key, and then builds a SQL
+ from the local table based on primary key, and then builds an SQL
<command>INSERT</command> command that will duplicate that row, but with
the primary key values replaced by the values in the last argument.
(To make an exact copy of the row, just specify the same values for
<para>
<function>dblink_build_sql_delete</function> can be useful in doing selective
- replication of a local table to a remote database. It builds a SQL
+ replication of a local table to a remote database. It builds an SQL
<command>DELETE</command> command that will delete the row with the given
primary key values.
</para>
<para>
<function>dblink_build_sql_update</function> can be useful in doing selective
replication of a local table to a remote database. It selects a row
- from the local table based on primary key, and then builds a SQL
+ from the local table based on primary key, and then builds an SQL
<command>UPDATE</command> command that will duplicate that row, but with
the primary key values replaced by the values in the last argument.
(To make an exact copy of the row, just specify the same values for
</para>
<para>
- The third option is to declare a SQL identifier linked to
+ The third option is to declare an SQL identifier linked to
the connection, for example:
<programlisting>
EXEC SQL AT <replaceable>connection-name</replaceable> DECLARE <replaceable>statement-name</replaceable> STATEMENT;
EXEC SQL PREPARE <replaceable>statement-name</replaceable> FROM :<replaceable>dyn-string</replaceable>;
</programlisting>
- Once you link a SQL identifier to a connection, you execute dynamic SQL
+ Once you link an SQL identifier to a connection, you execute dynamic SQL
without an AT clause. Note that this option behaves like preprocessor
directives, therefore the link is enabled only in the file.
</para>
variables and vice-versa. However, when creating a statement ecpg does
not know the types of the columns, so that it cannot check if a C array
is input into a corresponding SQL-level array. When processing the
- output of a SQL statement, ecpg has the necessary information and thus
+ output of an SQL statement, ecpg has the necessary information and thus
checks if both are arrays.
</para>
parameters to a prepared query are:
</para>
<step><simpara>Create a prepared query (prepared statement)</simpara></step>
- <step><simpara>Declare a sqlda_t structure as an input SQLDA.</simpara></step>
+ <step><simpara>Declare an sqlda_t structure as an input SQLDA.</simpara></step>
<step><simpara>Allocate memory area (as sqlda_t structure) for the input SQLDA.</simpara></step>
<step><simpara>Set (copy) input values in the allocated memory.</simpara></step>
<step><simpara>Open a cursor with specifying the input SQLDA.</simpara></step>
EXEC SQL PREPARE stmt1 FROM :query;
EXEC SQL DECLARE cur1 CURSOR FOR stmt1;
- /* Create a SQLDA structure for an input parameter */
+ /* Create an SQLDA structure for an input parameter */
sqlda2 = (sqlda_t *)malloc(sizeof(sqlda_t) + sizeof(sqlvar_t));
memset(sqlda2, 0, sizeof(sqlda_t) + sizeof(sqlvar_t));
sqlda2->sqln = 2; /* a number of input variables */
<title>Description</title>
<para>
- <command>DECLARE STATEMENT</command> declares a SQL statement identifier.
+ <command>DECLARE STATEMENT</command> declares an SQL statement identifier.
SQL statement identifier can be associated with the connection.
When the identifier is used by dynamic SQL statements, the statements
are executed using the associated connection.
<term><replaceable class="parameter">statement_name</replaceable></term>
<listitem>
<para>
- The name of a SQL statement identifier, either as an SQL identifier or a host variable.
+ The name of an SQL statement identifier, either as an SQL identifier or a host variable.
</para>
</listitem>
</varlistentry>
and include the global <acronym>PGXS</acronym> makefile.
Here is an example that builds an extension module named
<literal>isbn_issn</literal>, consisting of a shared library containing
- some C code, an extension control file, a SQL script, an include file
+ some C code, an extension control file, an SQL script, an include file
(only needed if other modules might need to access the extension functions
without going via SQL), and a documentation text file:
<programlisting>
<returnvalue>json</returnvalue>
</para>
<para>
- Converts a SQL array to a JSON array. The behavior is the same
+ Converts an SQL array to a JSON array. The behavior is the same
as <function>to_json</function> except that line feeds will be added
between top-level array elements if the optional boolean parameter is
true.
<returnvalue>json</returnvalue>
</para>
<para>
- Converts a SQL composite value to a JSON object. The behavior is the
+ Converts an SQL composite value to a JSON object. The behavior is the
same as <function>to_json</function> except that line feeds will be
added between top-level elements if the optional boolean parameter is
true.
<itemizedlist spacing="compact">
<listitem>
<para>
- A JSON null value is converted to a SQL null in all cases.
+ A JSON null value is converted to an SQL null in all cases.
</para>
</listitem>
<listitem>
<literal>string</literal>, <literal>number</literal>,
<literal>boolean</literal>, and <literal>null</literal>.
(The <literal>null</literal> result should not be confused
- with a SQL NULL; see the examples.)
+ with an SQL NULL; see the examples.)
</para>
<para>
<literal>json_typeof('-123.4')</literal>
Currently, temporary table creation is not allowed during read only
transactions, so in some cases existing scripts will not run correctly.
This restriction might be relaxed in a later release. This is
- both a SQL Standard compliance issue and a technical issue.
+ both an SQL Standard compliance issue and a technical issue.
</para>
<para>
<para>
If the index AM wishes to cache data across successive index insertions
- within a SQL statement, it can allocate space
+ within an SQL statement, it can allocate space
in <literal>indexInfo->ii_Context</literal> and store a pointer to the
data in <literal>indexInfo->ii_AmCache</literal> (which will be NULL
initially).
<listitem>
<para>
The text of a failed internally-generated command. This could
- be, for example, a SQL query issued by a PL/pgSQL function.
+ be, for example, an SQL query issued by a PL/pgSQL function.
</para>
</listitem>
</varlistentry>
</indexterm>
<para>
- Ordinarily, <application>libpq</application> collects a SQL command's
+ Ordinarily, <application>libpq</application> collects an SQL command's
entire result and returns it to the application as a single
<structname>PGresult</structname>. This can be unworkable for commands
that return a large number of rows. For such cases, applications can use
</para>
<para>
- We could simplify this by creating a SQL function that inserts a label
+ We could simplify this by creating an SQL function that inserts a label
at a specified position in a path:
<screen>
CREATE FUNCTION ins_label(ltree, int, text) RETURNS ltree
transactions might do, or it will not successfully commit. It is
important that an environment which uses this technique have a
generalized way of handling serialization failures (which always return
- with a SQLSTATE value of '40001'), because it will be very hard to
+ with an SQLSTATE value of '40001'), because it will be very hard to
predict exactly which transactions might contribute to the read/write
dependencies and need to be rolled back to prevent serialization
anomalies. The monitoring of read/write dependencies has a cost, as does
<listitem>
<para>
<function>fsm_page_contents</function> shows the internal node structure
- of a FSM page. For example:
+ of an FSM page. For example:
<screen>
test=# SELECT fsm_page_contents(get_raw_page('pg_class', 'fsm', 0));
</screen>
</listitem>
<listitem>
<para>
- An SHA1 hash of the random prefix and data is appended.
+ A SHA1 hash of the random prefix and data is appended.
</para>
</listitem>
<listitem>
One might expect that writing <command>SELECT</command> directly
would accomplish this result, but at
present the only accepted way to do it is
- <command>PERFORM</command>. A SQL command that can return rows,
+ <command>PERFORM</command>. An SQL command that can return rows,
such as <command>SELECT</command>, will be rejected as an error
unless it has an <literal>INTO</literal> clause as discussed in the
next section.
</indexterm>
<para>
- The result of a SQL command yielding a single row (possibly of multiple
+ The result of an SQL command yielding a single row (possibly of multiple
columns) can be assigned to a record variable, row-type variable, or list
of scalar variables. This is done by writing the base SQL command and
adding an <literal>INTO</literal> clause. For example,
<para>
The <literal>INTO</literal> clause specifies where the results of
- a SQL command returning rows should be assigned. If a row variable
+ an SQL command returning rows should be assigned. If a row variable
or variable list is provided, it must exactly match the structure
of the command's results; if a
record variable is provided, it will configure itself to match the
<para>
The <literal>FOREACH</literal> loop is much like a <literal>FOR</literal> loop,
- but instead of iterating through the rows returned by a SQL query,
+ but instead of iterating through the rows returned by an SQL query,
it iterates through the elements of an array value.
(In general, <literal>FOREACH</literal> is meant for looping through
components of a composite-valued expression; variants for looping
<para>
Another way to understand this is that variable substitution can only
- insert data values into a SQL command; it cannot dynamically change which
+ insert data values into an SQL command; it cannot dynamically change which
database objects are referenced by the command. (If you want to do
that, you must build a command string dynamically, as explained in
<xref linkend="plpgsql-statements-executing-dyn"/>.)
<para>
By default, <application>PL/pgSQL</application> will report an error if a name
- in a SQL statement could refer to either a variable or a table column.
+ in an SQL statement could refer to either a variable or a table column.
You can fix such a problem by renaming the variable or column,
or by qualifying the ambiguous reference, or by telling
<application>PL/pgSQL</application> which interpretation to prefer.
<itemizedlist>
<listitem>
<para>
- If a name used in a SQL command could be either a column name of a
+ If a name used in an SQL command could be either a column name of a
table used in the command or a reference to a variable of the function,
<application>PL/SQL</application> treats it as a column name.
By default, <application>PL/pgSQL</application> will throw an error
$$ LANGUAGE plpythonu;
</programlisting>
- To return a SQL null for any column, insert <symbol>None</symbol> at
+ To return an SQL null for any column, insert <symbol>None</symbol> at
the corresponding position.
</para>
<para>
Any extra dictionary key/value pairs are ignored. Missing keys are
treated as errors.
- To return a SQL null value for any column, insert
+ To return an SQL null value for any column, insert
<symbol>None</symbol> with the corresponding column name as the key.
</para>
</listitem>
<listitem>
<para>
The Tcl script contained in <replaceable>command</replaceable> is
- executed within a SQL subtransaction. If the script returns an
+ executed within an SQL subtransaction. If the script returns an
error, that entire subtransaction is rolled back before returning the
error out to the surrounding Tcl code.
See <xref linkend="pltcl-subtransactions"/> for more details and an
PL/Tcl's <function>elog</function> command. Such errors can be caught
within Tcl using the Tcl <function>catch</function> command. If an
error is not caught but is allowed to propagate out to the top level of
- execution of the PL/Tcl function, it is reported as a SQL error in the
+ execution of the PL/Tcl function, it is reported as an SQL error in the
function's calling query.
</para>
subtransaction, which is rolled back on error, so that any
partially-completed operation is automatically cleaned up.)
Again, if an error propagates out to the top level without being caught,
- it turns back into a SQL error.
+ it turns back into an SQL error.
</para>
<para>
<term>AuthenticationSSPI</term>
<listitem>
<para>
- The frontend must now initiate a SSPI negotiation. The frontend
+ The frontend must now initiate an SSPI negotiation. The frontend
will send a GSSResponse with the first part of the SSPI
data stream in response to this. If further messages are needed,
the server will respond with AuthenticationGSSContinue.
<para>
One or more server-challenge and client-response message will follow. Each
server-challenge is sent in an AuthenticationSASLContinue message, followed
- by a response from client in an SASLResponse message. The particulars of
+ by a response from client in a SASLResponse message. The particulars of
the messages are mechanism specific.
</para>
</step>
<listitem>
<para>
Internal query: the text of a failed internally-generated command.
- This could be, for example, a SQL query issued by a PL/pgSQL function.
+ This could be, for example, an SQL query issued by a PL/pgSQL function.
</para>
</listitem>
</varlistentry>
</para>
<para>
- The operators should not be defined by SQL functions. A SQL function
+ The operators should not be defined by SQL functions. An SQL function
is likely to be inlined into the calling query, which will prevent
the optimizer from recognizing that the query matches an index.
</para>
<title>Examples</title>
<para>
- Add two integers using a SQL function:
+ Add two integers using an SQL function:
<programlisting>
CREATE FUNCTION add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
</para>
<para>
- The operators should not be defined by SQL functions. A SQL function
+ The operators should not be defined by SQL functions. An SQL function
is likely to be inlined into the calling query, which will prevent
the optimizer from recognizing that the query matches an index.
</para>
<para>
Create table <structname>t2</structname> with two perfectly correlated columns
- (containing identical data), and a MCV list on those columns:
+ (containing identical data), and an MCV list on those columns:
<programlisting>
CREATE TABLE t2 (
as <literal>ON UPDATE CASCADE</literal> or <literal>ON DELETE SET NULL</literal>, are
treated as part of the SQL command that caused them (note that such
actions are never deferred). Relevant triggers on the affected table will
- be fired, so that this provides another way in which a SQL command might
+ be fired, so that this provides another way in which an SQL command might
fire triggers not directly matching its type. In simple cases, triggers
that request transition relations will see all changes caused in their
table by a single original SQL command as a single transition relation.
<title>Examples</title>
<para>
- To dump a database called <literal>mydb</literal> into a SQL-script file:
+ To dump a database called <literal>mydb</literal> into an SQL-script file:
<screen>
<prompt>$</prompt> <userinput>pg_dump mydb > db.sql</userinput>
</screen>
Before <productname>PostgreSQL</productname> 9.6, SQL commands in script files
were terminated by newlines, and so they could not be continued across
lines. Now a semicolon is <emphasis>required</emphasis> to separate consecutive
- SQL commands (though a SQL command does not need one if it is followed
+ SQL commands (though an SQL command does not need one if it is followed
by a meta command). If you need to create a script file that works with
both old and new versions of <application>pgbench</application>, be sure to write
each SQL command on a single line ending with a semicolon.
<xref linkend="pgbench-automatic-variables"/>. A value specified for these
variables using <option>-D</option> takes precedence over the automatic presets.
Once set, a variable's
- value can be inserted into a SQL command by writing
+ value can be inserted into an SQL command by writing
<literal>:</literal><replaceable>variablename</replaceable>. When running more than
one client session, each session has its own set of variables.
<application>pgbench</application> supports up to 255 variable uses in one
For <literal>\copy ... from stdin</literal>, data rows are read from the same
source that issued the command, continuing until <literal>\.</literal>
is read or the stream reaches <acronym>EOF</acronym>. This option is useful
- for populating tables in-line within a SQL script file.
+ for populating tables in-line within an SQL script file.
For <literal>\copy ... to stdout</literal>, output is sent to the same place
as <application>psql</application> command output, and
the <literal>COPY <replaceable>count</replaceable></literal> command status is
<listitem>
<para>
Sends the current query buffer to the server, then treats
- each column of each row of the query's output (if any) as a SQL
+ each column of each row of the query's output (if any) as an SQL
statement to be executed. For example, to create an index on each
column of <structname>my_table</structname>:
<programlisting>
</para>
<para>
- Normally, <application>psql</application> will dispatch a SQL command to the
+ Normally, <application>psql</application> will dispatch an SQL command to the
server as soon as it reaches the command-ending semicolon, even if
more input remains on the current line. Thus for example entering
<programlisting>
row2 val21 val22 val23 ...
...
</programlisting>
- The <function>crosstab</function> function takes a text parameter that is a SQL
+ The <function>crosstab</function> function takes a text parameter that is an SQL
query producing raw data formatted in the first way, and produces a table
formatted in the second way.
</para>
<para>
- The <parameter>sql</parameter> parameter is a SQL statement that produces
+ The <parameter>sql</parameter> parameter is an SQL statement that produces
the source set of data. This statement must return one
<structfield>row_name</structfield> column, one
<structfield>category</structfield> column, and one
</para>
<para>
- <parameter>source_sql</parameter> is a SQL statement that produces the
+ <parameter>source_sql</parameter> is an SQL statement that produces the
source set of data. This statement must return one
<structfield>row_name</structfield> column, one
<structfield>category</structfield> column, and one
</para>
<para>
- <parameter>category_sql</parameter> is a SQL statement that produces
+ <parameter>category_sql</parameter> is an SQL statement that produces
the set of categories. This statement must return only one column.
It must produce at least one row, or an error will be generated.
Also, it must not produce duplicate values, or an error will be
The name of the function is the same method name appearing in the
<literal>TABLESAMPLE</literal> clause. The <type>internal</type> argument is a dummy
(always having value zero) that simply serves to prevent this function from
- being called directly from a SQL command.
+ being called directly from an SQL command.
The result of the function must be a palloc'd struct of
type <type>TsmRoutine</type>, which contains pointers to support functions for
the sampling method. These support functions are plain C functions and
<listitem>
<para>
This form of <function>ts_rewrite</function> accepts a starting
- <replaceable>query</replaceable> and a SQL <replaceable>select</replaceable> command, which
+ <replaceable>query</replaceable> and an SQL <replaceable>select</replaceable> command, which
is given as a text string. The <replaceable>select</replaceable> must yield two
columns of <type>tsquery</type> type. For each row of the
<replaceable>select</replaceable> result, occurrences of the first column value
trigger <emphasis>will</emphasis> see the effects of data
changes for rows previously processed in the same outer
command. This requires caution, since the ordering of these
- change events is not in general predictable; a SQL command that
+ change events is not in general predictable; an SQL command that
affects multiple rows can visit the rows in any order.
</para>
</listitem>
<para>
The rules given in the preceding sections will result in assignment
-of non-<type>unknown</type> data types to all expressions in a SQL query,
+of non-<type>unknown</type> data types to all expressions in an SQL query,
except for unspecified-type literals that appear as simple output
columns of a <command>SELECT</command> command. For example, in
must be a <command>SELECT</command> or have a <literal>RETURNING</literal>
clause that returns whatever is
specified as the function's return type. Alternatively, if you
- want to define a SQL function that performs actions but has no
+ want to define an SQL function that performs actions but has no
useful value to return, you can define it as returning <type>void</type>.
For example, this function removes rows with negative salaries from
the <literal>emp</literal> table:
<note>
<para>
- The entire body of a SQL function is parsed before any of it is
- executed. While a SQL function can contain commands that alter
+ The entire body of an SQL function is parsed before any of it is
+ executed. While an SQL function can contain commands that alter
the system catalogs (e.g., <command>CREATE TABLE</command>), the effects
of such commands will not be visible during parse analysis of
later commands in the function. Thus, for example,
will not work as desired if packaged up into a single SQL function,
since <structname>foo</structname> won't exist yet when the <command>INSERT</command>
command is parsed. It's recommended to use <application>PL/pgSQL</application>
- instead of a SQL function in this type of situation.
+ instead of an SQL function in this type of situation.
</para>
</note>
</indexterm>
<para>
- Arguments of a SQL function can be referenced in the function
+ Arguments of an SQL function can be referenced in the function
body using either names or numbers. Examples of both methods appear
below.
</para>
</indexterm>
<para>
- When a SQL function has one or more parameters of collatable data types,
+ When an SQL function has one or more parameters of collatable data types,
a collation is identified for each function call depending on the
collations assigned to the actual arguments, as described in <xref
linkend="collation"/>. If a collation is successfully identified
<para>
If no common collation can be identified among the actual arguments,
- then a SQL function treats its parameters as having their data types'
+ then an SQL function treats its parameters as having their data types'
default collation (which is usually the database's default collation,
but could be different for parameters of domain types).
</para>
save enough state across calls to remember what it was doing and
return the correct next item on each call.
In the other method, called <firstterm>Materialize</firstterm> mode,
- a SRF fills and returns a tuplestore object containing its
+ an SRF fills and returns a tuplestore object containing its
entire result; then only one call occurs for the whole result, and
no inter-call state is needed.
</para>
There is a variant of polymorphism that is only available to C-language
functions: they can be declared to take parameters of type
<literal>"any"</literal>. (Note that this type name must be double-quoted,
- since it's also a SQL reserved word.) This works like
+ since it's also an SQL reserved word.) This works like
<type>anyelement</type> except that it does not constrain different
<literal>"any"</literal> arguments to be the same type, nor do they help
determine the function's result type. A C-language function can also
<para>
It is also possible to attach a <firstterm>planner support
- function</firstterm> to a SQL-callable function (called
+ function</firstterm> to an SQL-callable function (called
its <firstterm>target function</firstterm>), and thereby provide
knowledge about the target function that is too complex to be
represented declaratively. Planner support functions have to be
((CopyStmt *) stmt->utilityStmt)->filename == NULL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("cannot COPY to/from client in a SQL function")));
+ errmsg("cannot COPY to/from client in an SQL function")));
if (IsA(stmt->utilityStmt, TransactionStmt))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
/* translator: %s is a SQL statement name */
- errmsg("%s is not allowed in a SQL function",
+ errmsg("%s is not allowed in an SQL function",
CreateCommandName(stmt->utilityStmt))));
}
if (index == 0)
syntax_error(desc, lineno, NULL, NULL,
- "\\gset must follow a SQL command",
+ "\\gset must follow an SQL command",
NULL, -1);
cmd = ps.commands[index - 1];
if (cmd->type != SQL_COMMAND ||
cmd->varprefix != NULL)
syntax_error(desc, lineno, NULL, NULL,
- "\\gset must follow a SQL command",
+ "\\gset must follow an SQL command",
cmd->first_line, -1);
/* get variable prefix */
'gset no row', 2,
[qr{expected one row, got 0\b}], q{SELECT WHERE FALSE \gset}
],
- [ 'gset alone', 1, [qr{gset must follow a SQL command}], q{\gset} ],
+ [ 'gset alone', 1, [qr{gset must follow an SQL command}], q{\gset} ],
[
'gset no SQL', 1,
- [qr{gset must follow a SQL command}], q{\set i +1
+ [qr{gset must follow an SQL command}], q{\set i +1
\gset}
],
[
],
[
'gset after gset', 1,
- [qr{gset must follow a SQL command}], q{SELECT 1 AS i \gset
+ [qr{gset must follow an SQL command}], q{SELECT 1 AS i \gset
\gset}
],
[