]> begriffs open source - ai-pg/blob - full-docs/man3/SPI_execute_with_args.3
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man3 / SPI_execute_with_args.3
1 '\" t
2 .\"     Title: SPI_execute_with_args
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "SPI_EXECUTE_WITH_ARGS" "3" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 SPI_execute_with_args \- execute a command with out\-of\-line parameters
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 int SPI_execute_with_args(const char *\fIcommand\fR,
36                           int \fInargs\fR, Oid *\fIargtypes\fR,
37                           Datum *\fIvalues\fR, const char *\fInulls\fR,
38                           bool \fIread_only\fR, long \fIcount\fR)
39 .fi
40 .SH "DESCRIPTION"
41 .PP
42 \fBSPI_execute_with_args\fR
43 executes a command that might include references to externally supplied parameters\&. The command text refers to a parameter as
44 $\fIn\fR, and the call specifies data types and values for each such symbol\&.
45 \fIread_only\fR
46 and
47 \fIcount\fR
48 have the same interpretation as in
49 \fBSPI_execute\fR\&.
50 .PP
51 The main advantage of this routine compared to
52 \fBSPI_execute\fR
53 is that data values can be inserted into the command without tedious quoting/escaping, and thus with much less risk of SQL\-injection attacks\&.
54 .PP
55 Similar results can be achieved with
56 \fBSPI_prepare\fR
57 followed by
58 \fBSPI_execute_plan\fR; however, when using this function the query plan is always customized to the specific parameter values provided\&. For one\-time query execution, this function should be preferred\&. If the same command is to be executed with many different parameters, either method might be faster, depending on the cost of re\-planning versus the benefit of custom plans\&.
59 .SH "ARGUMENTS"
60 .PP
61 const char * \fIcommand\fR
62 .RS 4
63 command string
64 .RE
65 .PP
66 int \fInargs\fR
67 .RS 4
68 number of input parameters ($1,
69 $2, etc\&.)
70 .RE
71 .PP
72 Oid * \fIargtypes\fR
73 .RS 4
74 an array of length
75 \fInargs\fR, containing the
76 OIDs of the data types of the parameters
77 .RE
78 .PP
79 Datum * \fIvalues\fR
80 .RS 4
81 an array of length
82 \fInargs\fR, containing the actual parameter values
83 .RE
84 .PP
85 const char * \fInulls\fR
86 .RS 4
87 an array of length
88 \fInargs\fR, describing which parameters are null
89 .sp
90 If
91 \fInulls\fR
92 is
93 NULL
94 then
95 \fBSPI_execute_with_args\fR
96 assumes that no parameters are null\&. Otherwise, each entry of the
97 \fInulls\fR
98 array should be
99 \*(Aq\ \&\*(Aq
100 if the corresponding parameter value is non\-null, or
101 \*(Aqn\*(Aq
102 if the corresponding parameter value is null\&. (In the latter case, the actual value in the corresponding
103 \fIvalues\fR
104 entry doesn\*(Aqt matter\&.) Note that
105 \fInulls\fR
106 is not a text string, just an array: it does not need a
107 \*(Aq\e0\*(Aq
108 terminator\&.
109 .RE
110 .PP
111 bool \fIread_only\fR
112 .RS 4
113 true
114 for read\-only execution
115 .RE
116 .PP
117 long \fIcount\fR
118 .RS 4
119 maximum number of rows to return, or
120 0
121 for no limit
122 .RE
123 .SH "RETURN VALUE"
124 .PP
125 The return value is the same as for
126 \fBSPI_execute\fR\&.
127 .PP
128 \fISPI_processed\fR
129 and
130 \fISPI_tuptable\fR
131 are set as in
132 \fBSPI_execute\fR
133 if successful\&.