File: spi-spi-prepare.html

package info (click to toggle)
pgadmin3 1.4.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 29,796 kB
  • ctags: 10,758
  • sloc: cpp: 55,356; sh: 6,164; ansic: 1,520; makefile: 576; sql: 482; xml: 100; perl: 18
file content (86 lines) | stat: -rw-r--r-- 4,627 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>SPI_prepare</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="spi.html#spi-interface" title="40.1.Interface Functions">
<link rel="prev" href="spi-spi-exec.html" title="SPI_exec">
<link rel="next" href="spi-spi-getargcount.html" title="SPI_getargcount">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
<a name="spi-spi-prepare"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>Name</h2>
<p>SPI_prepare &#8212; prepare a plan for a command, without executing it yet</p>
</div>
<a name="id735240"></a><div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">void * SPI_prepare(const char * <em class="parameter"><code>command</code></em>, int <em class="parameter"><code>nargs</code></em>, Oid * <em class="parameter"><code>argtypes</code></em>)</pre>
</div>
<div class="refsect1" lang="en">
<a name="id735273"></a><h2>Description</h2>
<p>   <code class="function">SPI_prepare</code> creates and returns an execution
   plan for the specified command but doesn't execute the command.
   This function should only be called from a connected procedure.
  </p>
<p>   When the same or a similar command is to be executed repeatedly, it
   may be advantageous to perform the planning only once.
   <code class="function">SPI_prepare</code> converts a command string into an
   execution plan that can be executed repeatedly using
   <code class="function">SPI_execute_plan</code>.
  </p>
<p>   A prepared command can be generalized by writing parameters
   (<code class="literal">$1</code>, <code class="literal">$2</code>, etc.) in place of what would be
   constants in a normal command.  The actual values of the parameters
   are then specified when <code class="function">SPI_execute_plan</code> is called.
   This allows the prepared command to be used over a wider range of
   situations than would be possible without parameters.
  </p>
<p>   The plan returned by <code class="function">SPI_prepare</code> can be used
   only in the current invocation of the procedure, since
   <code class="function">SPI_finish</code> frees memory allocated for a plan.
   But a plan can be saved for longer using the function
   <code class="function">SPI_saveplan</code>.
  </p>
</div>
<div class="refsect1" lang="en">
<a name="id735362"></a><h2>Arguments</h2>
<div class="variablelist"><dl>
<dt><span class="term"><code class="literal">const char * <em class="parameter"><code>command</code></em></code></span></dt>
<dd><p>      command string
     </p></dd>
<dt><span class="term"><code class="literal">int <em class="parameter"><code>nargs</code></em></code></span></dt>
<dd><p>      number of input parameters (<code class="literal">$1</code>, <code class="literal">$2</code>, etc.)
     </p></dd>
<dt><span class="term"><code class="literal">Oid * <em class="parameter"><code>argtypes</code></em></code></span></dt>
<dd><p>      pointer to an array containing the <acronym class="acronym">OID</acronym>s of
      the data types of the parameters
     </p></dd>
</dl></div>
</div>
<div class="refsect1" lang="en">
<a name="id735435"></a><h2>Return Value</h2>
<p>   <code class="function">SPI_prepare</code> returns a non-null pointer to an
   execution plan.  On error, <code class="symbol">NULL</code> will be returned,
   and <code class="varname">SPI_result</code> will be set to one of the same
   error codes used by <code class="function">SPI_execute</code>, except that
   it is set to <code class="symbol">SPI_ERROR_ARGUMENT</code> if
   <em class="parameter"><code>command</code></em> is <code class="symbol">NULL</code>, or if
   <em class="parameter"><code>nargs</code></em> is less than 0, or if <em class="parameter"><code>nargs</code></em> is
   greater than 0 and <em class="parameter"><code>argtypes</code></em> is <code class="symbol">NULL</code>.
  </p>
</div>
<div class="refsect1" lang="en">
<a name="id735506"></a><h2>Notes</h2>
<p>   There is a disadvantage to using parameters: since the planner does
   not know the values that will be supplied for the parameters, it
   may make worse planning choices than it would make for a normal
   command with all constants visible.
  </p>
</div>
</div></body>
</html>