summaryrefslogtreecommitdiff
path: root/doc/src/sgml/ref/prepare.sgml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/sgml/ref/prepare.sgml')
-rw-r--r--doc/src/sgml/ref/prepare.sgml42
1 files changed, 25 insertions, 17 deletions
diff --git a/doc/src/sgml/ref/prepare.sgml b/doc/src/sgml/ref/prepare.sgml
index 51c3985117..738b6320a4 100644
--- a/doc/src/sgml/ref/prepare.sgml
+++ b/doc/src/sgml/ref/prepare.sgml
@@ -1,5 +1,5 @@
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/prepare.sgml,v 1.17 2006/01/08 07:00:25 neilc Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/prepare.sgml,v 1.18 2006/01/15 22:18:46 neilc Exp $
PostgreSQL documentation
-->
@@ -25,7 +25,7 @@ PostgreSQL documentation
<refsynopsisdiv>
<synopsis>
-PREPARE <replaceable class="PARAMETER">plan_name</replaceable> [ (<replaceable class="PARAMETER">datatype</replaceable> [, ...] ) ] AS <replaceable class="PARAMETER">statement</replaceable>
+PREPARE <replaceable class="PARAMETER">name</replaceable> [ (<replaceable class="PARAMETER">datatype</replaceable> [, ...] ) ] AS <replaceable class="PARAMETER">statement</replaceable>
</synopsis>
</refsynopsisdiv>
@@ -45,13 +45,15 @@ PREPARE <replaceable class="PARAMETER">plan_name</replaceable> [ (<replaceable c
<para>
Prepared statements can take parameters: values that are
- substituted into the statement when it is executed. To include
- parameters in a prepared statement, supply a list of data types in
- the <command>PREPARE</command> statement, and, in the statement to
- be prepared itself, refer to the parameters by position using
- <literal>$1</literal>, <literal>$2</literal>, etc. When executing
- the statement, specify the actual values for these parameters in
- the <command>EXECUTE</command> statement. Refer to <xref
+ substituted into the statement when it is executed. When creating
+ the prepared statement, refer to parameters by position, using
+ <literal>$1</>, <literal>$2</>, etc. A corresponding list of
+ parameter data types can optionally be specified. When a
+ parameter's data type is not specified or is declared as
+ <literal>unknown</literal>, the type is inferred from the context
+ in which the parameter is used (if possible). When executing the
+ statement, specify the actual values for these parameters in the
+ <command>EXECUTE</command> statement. Refer to <xref
linkend="sql-execute" endterm="sql-execute-title"> for more
information about that.
</para>
@@ -84,7 +86,7 @@ PREPARE <replaceable class="PARAMETER">plan_name</replaceable> [ (<replaceable c
<variablelist>
<varlistentry>
- <term><replaceable class="PARAMETER">plan_name</replaceable></term>
+ <term><replaceable class="PARAMETER">name</replaceable></term>
<listitem>
<para>
An arbitrary name given to this particular prepared
@@ -99,8 +101,11 @@ PREPARE <replaceable class="PARAMETER">plan_name</replaceable> [ (<replaceable c
<term><replaceable class="PARAMETER">datatype</replaceable></term>
<listitem>
<para>
- The data type of a parameter to the prepared statement. To
- refer to the parameters in the prepared statement itself, use
+ The data type of a parameter to the prepared statement. If the
+ data type of a particular parameter is unspecified or is
+ specified as <literal>unknown</literal>, it will be inferred
+ from the context in which the parameter is used. To refer to the
+ parameters in the prepared statement itself, use
<literal>$1</literal>, <literal>$2</literal>, etc.
</para>
</listitem>
@@ -155,8 +160,8 @@ PREPARE <replaceable class="PARAMETER">plan_name</replaceable> [ (<replaceable c
<refsect1 id="sql-prepare-examples">
<title id="sql-prepare-examples-title">Examples</title>
<para>
- Create a prepared query for an <command>INSERT</command> statement,
- and then execute it:
+ Create a prepared statement for an <command>INSERT</command>
+ statement, and then execute it:
<programlisting>
PREPARE fooplan (int, text, bool, numeric) AS
INSERT INTO foo VALUES($1, $2, $3, $4);
@@ -165,14 +170,17 @@ EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00);
</para>
<para>
- Create a prepared query for a <command>SELECT</command> statement,
- and then execute it:
+ Create a prepared statement for a <command>SELECT</command>
+ statement, and then execute it:
<programlisting>
-PREPARE usrrptplan (int, date) AS
+PREPARE usrrptplan (int) AS
SELECT * FROM users u, logs l WHERE u.usrid=$1 AND u.usrid=l.usrid
AND l.date = $2;
EXECUTE usrrptplan(1, current_date);
</programlisting>
+
+ Note that the data type of the second parameter is not specified,
+ so it is inferred from the context in which <literal>$2</> is used.
</para>
</refsect1>
<refsect1>