Commit 2f48836b authored by Tom Lane's avatar Tom Lane

Some editorializing on the docs for the dollar-quoting feature: fix

grammar, don't drop discussions into the middle of unrelated discussions,
etc.
parent 5b564e53
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.149 2004/09/20 04:19:50 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.150 2004/09/20 22:48:25 tgl Exp $
--> -->
<chapter id="datatype"> <chapter id="datatype">
...@@ -507,6 +507,16 @@ NUMERIC ...@@ -507,6 +507,16 @@ NUMERIC
declared limits, an error is raised. declared limits, an error is raised.
</para> </para>
<para>
In addition to ordinary numeric values, the <type>numeric</type>
type allows the special value <literal>NaN</>, meaning
<quote>not-a-number</quote>. Any operation on <literal>NaN</>
yields another <literal>NaN</>. When writing this value
as a constant in a SQL command, you must put quotes around it,
for example <literal>UPDATE table SET x = 'NaN'</>. On input,
the string <literal>NaN</> is recognized in a case-insensitive manner.
</para>
<para> <para>
The types <type>decimal</type> and <type>numeric</type> are The types <type>decimal</type> and <type>numeric</type> are
equivalent. Both types are part of the <acronym>SQL</acronym> equivalent. Both types are part of the <acronym>SQL</acronym>
...@@ -595,6 +605,24 @@ NUMERIC ...@@ -595,6 +605,24 @@ NUMERIC
from zero will cause an underflow error. from zero will cause an underflow error.
</para> </para>
<para>
In addition to ordinary numeric values, the floating-point types
have several special values:
<literallayout>
<literal>Infinity</literal>
<literal>-Infinity</literal>
<literal>NaN</literal>
</literallayout>
These represent the IEEE 754 special values
<quote>infinity</quote>, <quote>negative infinity</quote>, and
<quote>not-a-number</quote>, respectively. (On a machine whose
floating-point arithmetic does not follow IEEE 754, these values
will probably not work as expected.) When writing these values
as constants in a SQL command, you must put quotes around them,
for example <literal>UPDATE table SET x = 'Infinity'</>. On input,
these strings are recognized in a case-insensitive manner.
</para>
<para> <para>
<productname>PostgreSQL</productname> also supports the SQL-standard <productname>PostgreSQL</productname> also supports the SQL-standard
notations <type>float</type> and notations <type>float</type> and
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.27 2004/08/18 03:37:56 momjian Exp $ $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.28 2004/09/20 22:48:25 tgl Exp $
--> -->
<chapter id="plperl"> <chapter id="plperl">
...@@ -47,19 +47,24 @@ $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.27 2004/08/18 03:37:56 momjian E ...@@ -47,19 +47,24 @@ $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.27 2004/08/18 03:37:56 momjian E
<para> <para>
To create a function in the PL/Perl language, use the standard syntax: To create a function in the PL/Perl language, use the standard syntax:
<programlisting> <programlisting>
CREATE FUNCTION <replaceable>funcname</replaceable> CREATE FUNCTION <replaceable>funcname</replaceable> (<replaceable>argument-types</replaceable>) RETURNS <replaceable>return-type</replaceable> AS $$
(<replaceable>argument-types</replaceable>) RETURNS <replaceable>return-type</replaceable> AS $$
# PL/Perl function body # PL/Perl function body
$$ LANGUAGE plperl; $$ LANGUAGE plperl;
</programlisting> </programlisting>
The body of the function is ordinary Perl code. Since the body of The body of the function is ordinary Perl code.
the function is treated as a string by
<productname>PostgreSQL</productname>, it can be specified using
dollar quoting (as shown above), or via the legacy single quote
syntax (see <xref linkend="sql-syntax-strings"> for more
information).
</para> </para>
<para>
The syntax of the <command>CREATE FUNCTION</command> command requires
the function body to be written as a string constant. It is usually
most convenient to use dollar quoting (see <xref
linkend="sql-syntax-dollar-quoting">) for the string constant.
If you choose to use regular single-quoted string constant syntax,
you must escape single quote marks (<literal>'</>) and backslashes
(<literal>\</>) used in the body of the function, typically by
doubling them (see <xref linkend="sql-syntax-strings">).
</para>
<para> <para>
Arguments and results are handled as in any other Perl subroutine: Arguments and results are handled as in any other Perl subroutine:
Arguments are passed in <varname>@_</varname>, and a result value Arguments are passed in <varname>@_</varname>, and a result value
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/pltcl.sgml,v 2.30 2004/05/16 23:22:07 neilc Exp $ $PostgreSQL: pgsql/doc/src/sgml/pltcl.sgml,v 2.31 2004/09/20 22:48:25 tgl Exp $
--> -->
<chapter id="pltcl"> <chapter id="pltcl">
...@@ -400,7 +400,7 @@ $$ LANGUAGE pltcl; ...@@ -400,7 +400,7 @@ $$ LANGUAGE pltcl;
<term><function>quote</> <replaceable>string</replaceable></term> <term><function>quote</> <replaceable>string</replaceable></term>
<listitem> <listitem>
<para> <para>
Duplicates all occurrences of single quote and backslash characters Doubles all occurrences of single quote and backslash characters
in the given string. This may be used to safely quote strings in the given string. This may be used to safely quote strings
that are to be inserted into SQL commands given that are to be inserted into SQL commands given
to <function>spi_exec</function> or to <function>spi_exec</function> or
...@@ -422,10 +422,10 @@ SELECT 'doesn't' AS ret ...@@ -422,10 +422,10 @@ SELECT 'doesn't' AS ret
which would cause a parse error during which would cause a parse error during
<function>spi_exec</function> or <function>spi_exec</function> or
<function>spi_prepare</function>. <function>spi_prepare</function>.
The submitted command should contain To work properly, the submitted command should contain
<programlisting> <programlisting>
SELECT $q$doesn't$q$ AS ret SELECT 'doesn''t' AS ret
</programlisting> </programlisting>
which can be formed in PL/Tcl using which can be formed in PL/Tcl using
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.60 2004/09/16 04:16:08 neilc Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.61 2004/09/20 22:48:29 tgl Exp $
--> -->
<refentry id="SQL-CREATEFUNCTION"> <refentry id="SQL-CREATEFUNCTION">
...@@ -264,16 +264,9 @@ CREATE [ OR REPLACE ] FUNCTION <replaceable class="parameter">name</replaceable> ...@@ -264,16 +264,9 @@ CREATE [ OR REPLACE ] FUNCTION <replaceable class="parameter">name</replaceable>
<listitem> <listitem>
<para> <para>
A string defining the function; the meaning depends on the A string constant defining the function; the meaning depends on the
language. It may be an internal function name, the path to an language. It may be an internal function name, the path to an
object file, an SQL command, or text in a procedural object file, an SQL command, or text in a procedural language.
language. When this string contains the text of a procedural
language function definition, it may be helpful to use dollar
quoting to specify this string, rather than the normal single
quote syntax (this avoids the need to escape any single quotes
that occur in the function definition itself). For more
information on dollar quoting, see <xref
linkend="sql-syntax-strings">.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -378,10 +371,13 @@ CREATE [ OR REPLACE ] FUNCTION <replaceable class="parameter">name</replaceable> ...@@ -378,10 +371,13 @@ CREATE [ OR REPLACE ] FUNCTION <replaceable class="parameter">name</replaceable>
functions. functions.
</para> </para>
<para> <para>
Unless dollar quoting is used, any single quotes or backslashes in It is often helpful to use dollar quoting (see <xref
the function definition must be escaped by doubling them. linkend="sql-syntax-dollar-quoting">) to write the function definition
</para> string, rather than the normal single quote syntax. Without dollar
quoting, any single quotes or backslashes in the function definition must
be escaped by doubling them.
</para>
<para> <para>
To be able to define a function, the user must have the To be able to define a function, the user must have the
...@@ -410,9 +406,9 @@ CREATE FUNCTION add(integer, integer) RETURNS integer ...@@ -410,9 +406,9 @@ CREATE FUNCTION add(integer, integer) RETURNS integer
<programlisting> <programlisting>
CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS ' CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS '
BEGIN BEGIN
RETURN i + 1; RETURN i + 1;
END;' LANGUAGE plpgsql; END;' LANGUAGE plpgsql;
</programlisting> </programlisting>
</para> </para>
</refsect1> </refsect1>
......
This diff is collapsed.
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.87 2004/09/13 20:05:25 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.88 2004/09/20 22:48:25 tgl Exp $
--> -->
<sect1 id="xfunc"> <sect1 id="xfunc">
...@@ -103,21 +103,28 @@ $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.87 2004/09/13 20:05:25 tgl Exp $ ...@@ -103,21 +103,28 @@ $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.87 2004/09/13 20:05:25 tgl Exp $
</para> </para>
<para> <para>
The body of an SQL function should be a list of one or more SQL The body of an SQL function must be a list of SQL
statements separated by semicolons. Although dollar quoting statements separated by semicolons. A semicolon after the last
obviates this, note that because the syntax of the <command>CREATE statement is optional. Unless the function is declared to return
FUNCTION</command> command, if you choose not to use dollar <type>void</>, the last statement must be a <command>SELECT</>.
quoting, i.e. the body of the function is enclosed in single quotes,
you must escape single quote marks (<literal>'</>) used in the body of
the function, either by writing two single quotes (<literal>''</>) or
with a backslash (<literal>\'</>) where you desire each quote to be.
</para> </para>
<para> <para>
Arguments to the SQL function may be referenced in the function The syntax of the <command>CREATE FUNCTION</command> command requires
body using the syntax <literal>$<replaceable>n</></>: <literal>$1</> refers to the function body to be written as a string constant. It is usually
the first argument, <literal>$2</> to the second, and so on. If an argument most convenient to use dollar quoting (see <xref
is of a composite type, then the dot notation, linkend="sql-syntax-dollar-quoting">) for the string constant.
If you choose to use regular single-quoted string constant syntax,
you must escape single quote marks (<literal>'</>) and backslashes
(<literal>\</>) used in the body of the function, typically by
doubling them (see <xref linkend="sql-syntax-strings">).
</para>
<para>
Arguments to the SQL function are referenced in the function
body using the syntax <literal>$<replaceable>n</></>: <literal>$1</>
refers to the first argument, <literal>$2</> to the second, and so on.
If an argument is of a composite type, then the dot notation,
e.g., <literal>$1.name</literal>, may be used to access attributes e.g., <literal>$1.name</literal>, may be used to access attributes
of the argument. of the argument.
</para> </para>
...@@ -664,7 +671,7 @@ DETAIL: A function returning "anyarray" or "anyelement" must have at least one ...@@ -664,7 +671,7 @@ DETAIL: A function returning "anyarray" or "anyelement" must have at least one
create an alias for the <function>sqrt</function> function: create an alias for the <function>sqrt</function> function:
<programlisting> <programlisting>
CREATE FUNCTION square_root(double precision) RETURNS double precision CREATE FUNCTION square_root(double precision) RETURNS double precision
AS $$dsqrt$$ AS 'dsqrt'
LANGUAGE internal LANGUAGE internal
STRICT; STRICT;
</programlisting> </programlisting>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment