]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/ecpg-errors.html
PG 18 docs from https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0-docs...
[ai-pg] / full-docs / src / sgml / html / ecpg-errors.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>34.8. Error Handling</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="ecpg-descriptors.html" title="34.7. Using Descriptor Areas" /><link rel="next" href="ecpg-preproc.html" title="34.9. Preprocessor Directives" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">34.8. Error Handling</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="ecpg-descriptors.html" title="34.7. Using Descriptor Areas">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="ecpg.html" title="Chapter 34. ECPG — Embedded SQL in C">Up</a></td><th width="60%" align="center">Chapter 34. <span class="application">ECPG</span> — Embedded <acronym class="acronym">SQL</acronym> in C</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="ecpg-preproc.html" title="34.9. Preprocessor Directives">Next</a></td></tr></table><hr /></div><div class="sect1" id="ECPG-ERRORS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">34.8. Error Handling <a href="#ECPG-ERRORS" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="ecpg-errors.html#ECPG-WHENEVER">34.8.1. Setting Callbacks</a></span></dt><dt><span class="sect2"><a href="ecpg-errors.html#ECPG-SQLCA">34.8.2. sqlca</a></span></dt><dt><span class="sect2"><a href="ecpg-errors.html#ECPG-SQLSTATE-SQLCODE">34.8.3. <code class="literal">SQLSTATE</code> vs. <code class="literal">SQLCODE</code></a></span></dt></dl></div><p>
3    This section describes how you can handle exceptional conditions
4    and warnings in an embedded SQL program.  There are two
5    nonexclusive facilities for this.
6
7    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
8       Callbacks can be configured to handle warning and error
9       conditions using the <code class="literal">WHENEVER</code> command.
10      </li><li class="listitem">
11       Detailed information about the error or warning can be obtained
12       from the <code class="varname">sqlca</code> variable.
13      </li></ul></div><p>
14   </p><div class="sect2" id="ECPG-WHENEVER"><div class="titlepage"><div><div><h3 class="title">34.8.1. Setting Callbacks <a href="#ECPG-WHENEVER" class="id_link">#</a></h3></div></div></div><p>
15     One simple method to catch errors and warnings is to set a
16     specific action to be executed whenever a particular condition
17     occurs.  In general:
18 </p><pre class="programlisting">
19 EXEC SQL WHENEVER <em class="replaceable"><code>condition</code></em> <em class="replaceable"><code>action</code></em>;
20 </pre><p>
21    </p><p>
22     <em class="replaceable"><code>condition</code></em> can be one of the following:
23
24     </p><div class="variablelist"><dl class="variablelist"><dt id="ECPG-WHENEVER-SQLERROR"><span class="term"><code class="literal">SQLERROR</code></span> <a href="#ECPG-WHENEVER-SQLERROR" class="id_link">#</a></dt><dd><p>
25         The specified action is called whenever an error occurs during
26         the execution of an SQL statement.
27        </p></dd><dt id="ECPG-WHENEVER-SQLWARNING"><span class="term"><code class="literal">SQLWARNING</code></span> <a href="#ECPG-WHENEVER-SQLWARNING" class="id_link">#</a></dt><dd><p>
28         The specified action is called whenever a warning occurs
29         during the execution of an SQL statement.
30        </p></dd><dt id="ECPG-WHENEVER-NOT-FOUND"><span class="term"><code class="literal">NOT FOUND</code></span> <a href="#ECPG-WHENEVER-NOT-FOUND" class="id_link">#</a></dt><dd><p>
31         The specified action is called whenever an SQL statement
32         retrieves or affects zero rows.  (This condition is not an
33         error, but you might be interested in handling it specially.)
34        </p></dd></dl></div><p>
35    </p><p>
36     <em class="replaceable"><code>action</code></em> can be one of the following:
37
38     </p><div class="variablelist"><dl class="variablelist"><dt id="ECPG-WHENEVER-CONTINUE"><span class="term"><code class="literal">CONTINUE</code></span> <a href="#ECPG-WHENEVER-CONTINUE" class="id_link">#</a></dt><dd><p>
39         This effectively means that the condition is ignored.  This is
40         the default.
41        </p></dd><dt id="ECPG-WHENEVER-GOTO"><span class="term"><code class="literal">GOTO <em class="replaceable"><code>label</code></em></code><br /></span><span class="term"><code class="literal">GO TO <em class="replaceable"><code>label</code></em></code></span> <a href="#ECPG-WHENEVER-GOTO" class="id_link">#</a></dt><dd><p>
42         Jump to the specified label (using a C <code class="literal">goto</code>
43         statement).
44        </p></dd><dt id="ECPG-WHENEVER-SQLPRINT"><span class="term"><code class="literal">SQLPRINT</code></span> <a href="#ECPG-WHENEVER-SQLPRINT" class="id_link">#</a></dt><dd><p>
45         Print a message to standard error.  This is useful for simple
46         programs or during prototyping.  The details of the message
47         cannot be configured.
48        </p></dd><dt id="ECPG-WHENEVER-STOP"><span class="term"><code class="literal">STOP</code></span> <a href="#ECPG-WHENEVER-STOP" class="id_link">#</a></dt><dd><p>
49         Call <code class="literal">exit(1)</code>, which will terminate the
50         program.
51        </p></dd><dt id="ECPG-WHENEVER-DO-BREAK"><span class="term"><code class="literal">DO BREAK</code></span> <a href="#ECPG-WHENEVER-DO-BREAK" class="id_link">#</a></dt><dd><p>
52         Execute the C statement <code class="literal">break</code>.  This should
53         only be used in loops or <code class="literal">switch</code> statements.
54        </p></dd><dt id="ECPG-WHENEVER-DO-CONTINUE"><span class="term"><code class="literal">DO CONTINUE</code></span> <a href="#ECPG-WHENEVER-DO-CONTINUE" class="id_link">#</a></dt><dd><p>
55         Execute the C statement <code class="literal">continue</code>.  This should
56         only be used in loops statements.  if executed, will cause the flow
57         of control to return to the top of the loop.
58        </p></dd><dt id="ECPG-WHENEVER-CALL"><span class="term"><code class="literal">CALL <em class="replaceable"><code>name</code></em> (<em class="replaceable"><code>args</code></em>)</code><br /></span><span class="term"><code class="literal">DO <em class="replaceable"><code>name</code></em> (<em class="replaceable"><code>args</code></em>)</code></span> <a href="#ECPG-WHENEVER-CALL" class="id_link">#</a></dt><dd><p>
59         Call the specified C functions with the specified arguments.  (This
60         use is different from the meaning of <code class="literal">CALL</code>
61         and <code class="literal">DO</code> in the normal PostgreSQL grammar.)
62        </p></dd></dl></div><p>
63
64     The SQL standard only provides for the actions
65     <code class="literal">CONTINUE</code> and <code class="literal">GOTO</code> (and
66     <code class="literal">GO TO</code>).
67    </p><p>
68     Here is an example that you might want to use in a simple program.
69     It prints a simple message when a warning occurs and aborts the
70     program when an error happens:
71 </p><pre class="programlisting">
72 EXEC SQL WHENEVER SQLWARNING SQLPRINT;
73 EXEC SQL WHENEVER SQLERROR STOP;
74 </pre><p>
75    </p><p>
76     The statement <code class="literal">EXEC SQL WHENEVER</code> is a directive
77     of the SQL preprocessor, not a C statement.  The error or warning
78     actions that it sets apply to all embedded SQL statements that
79     appear below the point where the handler is set, unless a
80     different action was set for the same condition between the first
81     <code class="literal">EXEC SQL WHENEVER</code> and the SQL statement causing
82     the condition, regardless of the flow of control in the C program.
83     So neither of the two following C program excerpts will have the
84     desired effect:
85 </p><pre class="programlisting">
86 /*
87  * WRONG
88  */
89 int main(int argc, char *argv[])
90 {
91     ...
92     if (verbose) {
93         EXEC SQL WHENEVER SQLWARNING SQLPRINT;
94     }
95     ...
96     EXEC SQL SELECT ...;
97     ...
98 }
99 </pre><p>
100
101 </p><pre class="programlisting">
102 /*
103  * WRONG
104  */
105 int main(int argc, char *argv[])
106 {
107     ...
108     set_error_handler();
109     ...
110     EXEC SQL SELECT ...;
111     ...
112 }
113
114 static void set_error_handler(void)
115 {
116     EXEC SQL WHENEVER SQLERROR STOP;
117 }
118 </pre><p>
119    </p></div><div class="sect2" id="ECPG-SQLCA"><div class="titlepage"><div><div><h3 class="title">34.8.2. sqlca <a href="#ECPG-SQLCA" class="id_link">#</a></h3></div></div></div><p>
120     For more powerful error handling, the embedded SQL interface
121     provides a global variable with the name <code class="varname">sqlca</code>
122     (SQL communication area)
123     that has the following structure:
124 </p><pre class="programlisting">
125 struct
126 {
127     char sqlcaid[8];
128     long sqlabc;
129     long sqlcode;
130     struct
131     {
132         int sqlerrml;
133         char sqlerrmc[SQLERRMC_LEN];
134     } sqlerrm;
135     char sqlerrp[8];
136     long sqlerrd[6];
137     char sqlwarn[8];
138     char sqlstate[5];
139 } sqlca;
140 </pre><p>
141     (In a multithreaded program, every thread automatically gets its
142     own copy of <code class="varname">sqlca</code>.  This works similarly to the
143     handling of the standard C global variable
144     <code class="varname">errno</code>.)
145    </p><p>
146     <code class="varname">sqlca</code> covers both warnings and errors.  If
147     multiple warnings or errors occur during the execution of a
148     statement, then <code class="varname">sqlca</code> will only contain
149     information about the last one.
150    </p><p>
151     If no error occurred in the last <acronym class="acronym">SQL</acronym> statement,
152     <code class="literal">sqlca.sqlcode</code> will be 0 and
153     <code class="literal">sqlca.sqlstate</code> will be
154     <code class="literal">"00000"</code>.  If a warning or error occurred, then
155     <code class="literal">sqlca.sqlcode</code> will be negative and
156     <code class="literal">sqlca.sqlstate</code> will be different from
157     <code class="literal">"00000"</code>.  A positive
158     <code class="literal">sqlca.sqlcode</code> indicates a harmless condition,
159     such as that the last query returned zero rows.
160     <code class="literal">sqlcode</code> and <code class="literal">sqlstate</code> are two
161     different error code schemes; details appear below.
162    </p><p>
163     If the last SQL statement was successful, then
164     <code class="literal">sqlca.sqlerrd[1]</code> contains the OID of the
165     processed row, if applicable, and
166     <code class="literal">sqlca.sqlerrd[2]</code> contains the number of
167     processed or returned rows, if applicable to the command.
168    </p><p>
169     In case of an error or warning,
170     <code class="literal">sqlca.sqlerrm.sqlerrmc</code> will contain a string
171     that describes the error.  The field
172     <code class="literal">sqlca.sqlerrm.sqlerrml</code> contains the length of
173     the error message that is stored in
174     <code class="literal">sqlca.sqlerrm.sqlerrmc</code> (the result of
175     <code class="function">strlen()</code>, not really interesting for a C
176     programmer).  Note that some messages are too long to fit in the
177     fixed-size <code class="literal">sqlerrmc</code> array; they will be truncated.
178    </p><p>
179     In case of a warning, <code class="literal">sqlca.sqlwarn[2]</code> is set
180     to <code class="literal">W</code>.  (In all other cases, it is set to
181     something different from <code class="literal">W</code>.)  If
182     <code class="literal">sqlca.sqlwarn[1]</code> is set to
183     <code class="literal">W</code>, then a value was truncated when it was
184     stored in a host variable.  <code class="literal">sqlca.sqlwarn[0]</code> is
185     set to <code class="literal">W</code> if any of the other elements are set
186     to indicate a warning.
187    </p><p>
188     The fields <code class="structfield">sqlcaid</code>,
189     <code class="structfield">sqlabc</code>,
190     <code class="structfield">sqlerrp</code>, and the remaining elements of
191     <code class="structfield">sqlerrd</code> and
192     <code class="structfield">sqlwarn</code> currently contain no useful
193     information.
194    </p><p>
195     The structure <code class="varname">sqlca</code> is not defined in the SQL
196     standard, but is implemented in several other SQL database
197     systems.  The definitions are similar at the core, but if you want
198     to write portable applications, then you should investigate the
199     different implementations carefully.
200    </p><p>
201     Here is one example that combines the use of <code class="literal">WHENEVER</code>
202     and <code class="varname">sqlca</code>, printing out the contents
203     of <code class="varname">sqlca</code> when an error occurs.  This is perhaps
204     useful for debugging or prototyping applications, before
205     installing a more <span class="quote">“<span class="quote">user-friendly</span>”</span> error handler.
206
207 </p><pre class="programlisting">
208 EXEC SQL WHENEVER SQLERROR CALL print_sqlca();
209
210 void
211 print_sqlca()
212 {
213     fprintf(stderr, "==== sqlca ====\n");
214     fprintf(stderr, "sqlcode: %ld\n", sqlca.sqlcode);
215     fprintf(stderr, "sqlerrm.sqlerrml: %d\n", sqlca.sqlerrm.sqlerrml);
216     fprintf(stderr, "sqlerrm.sqlerrmc: %s\n", sqlca.sqlerrm.sqlerrmc);
217     fprintf(stderr, "sqlerrd: %ld %ld %ld %ld %ld %ld\n", sqlca.sqlerrd[0],sqlca.sqlerrd[1],sqlca.sqlerrd[2],
218                                                           sqlca.sqlerrd[3],sqlca.sqlerrd[4],sqlca.sqlerrd[5]);
219     fprintf(stderr, "sqlwarn: %d %d %d %d %d %d %d %d\n", sqlca.sqlwarn[0], sqlca.sqlwarn[1], sqlca.sqlwarn[2],
220                                                           sqlca.sqlwarn[3], sqlca.sqlwarn[4], sqlca.sqlwarn[5],
221                                                           sqlca.sqlwarn[6], sqlca.sqlwarn[7]);
222     fprintf(stderr, "sqlstate: %5s\n", sqlca.sqlstate);
223     fprintf(stderr, "===============\n");
224 }
225 </pre><p>
226
227     The result could look as follows (here an error due to a
228     misspelled table name):
229
230 </p><pre class="screen">
231 ==== sqlca ====
232 sqlcode: -400
233 sqlerrm.sqlerrml: 49
234 sqlerrm.sqlerrmc: relation "pg_databasep" does not exist on line 38
235 sqlerrd: 0 0 0 0 0 0
236 sqlwarn: 0 0 0 0 0 0 0 0
237 sqlstate: 42P01
238 ===============
239 </pre><p>
240    </p></div><div class="sect2" id="ECPG-SQLSTATE-SQLCODE"><div class="titlepage"><div><div><h3 class="title">34.8.3. <code class="literal">SQLSTATE</code> vs. <code class="literal">SQLCODE</code> <a href="#ECPG-SQLSTATE-SQLCODE" class="id_link">#</a></h3></div></div></div><p>
241     The fields <code class="literal">sqlca.sqlstate</code> and
242     <code class="literal">sqlca.sqlcode</code> are two different schemes that
243     provide error codes.  Both are derived from the SQL standard, but
244     <code class="literal">SQLCODE</code> has been marked deprecated in the SQL-92
245     edition of the standard and has been dropped in later editions.
246     Therefore, new applications are strongly encouraged to use
247     <code class="literal">SQLSTATE</code>.
248    </p><p>
249     <code class="literal">SQLSTATE</code> is a five-character array.  The five
250     characters contain digits or upper-case letters that represent
251     codes of various error and warning conditions.
252     <code class="literal">SQLSTATE</code> has a hierarchical scheme: the first
253     two characters indicate the general class of the condition, the
254     last three characters indicate a subclass of the general
255     condition.  A successful state is indicated by the code
256     <code class="literal">00000</code>.  The <code class="literal">SQLSTATE</code> codes are for
257     the most part defined in the SQL standard.  The
258     <span class="productname">PostgreSQL</span> server natively supports
259     <code class="literal">SQLSTATE</code> error codes; therefore a high degree
260     of consistency can be achieved by using this error code scheme
261     throughout all applications.  For further information see
262     <a class="xref" href="errcodes-appendix.html" title="Appendix A. PostgreSQL Error Codes">Appendix A</a>.
263    </p><p>
264     <code class="literal">SQLCODE</code>, the deprecated error code scheme, is a
265     simple integer.  A value of 0 indicates success, a positive value
266     indicates success with additional information, a negative value
267     indicates an error.  The SQL standard only defines the positive
268     value +100, which indicates that the last command returned or
269     affected zero rows, and no specific negative values.  Therefore,
270     this scheme can only achieve poor portability and does not have a
271     hierarchical code assignment.  Historically, the embedded SQL
272     processor for <span class="productname">PostgreSQL</span> has assigned
273     some specific <code class="literal">SQLCODE</code> values for its use, which
274     are listed below with their numeric value and their symbolic name.
275     Remember that these are not portable to other SQL implementations.
276     To simplify the porting of applications to the
277     <code class="literal">SQLSTATE</code> scheme, the corresponding
278     <code class="literal">SQLSTATE</code> is also listed.  There is, however, no
279     one-to-one or one-to-many mapping between the two schemes (indeed
280     it is many-to-many), so you should consult the global
281     <code class="literal">SQLSTATE</code> listing in <a class="xref" href="errcodes-appendix.html" title="Appendix A. PostgreSQL Error Codes">Appendix A</a>
282     in each case.
283    </p><p>
284     These are the assigned <code class="literal">SQLCODE</code> values:
285
286     </p><div class="variablelist"><dl class="variablelist"><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NO-ERROR"><span class="term">0 (<code class="symbol">ECPG_NO_ERROR</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NO-ERROR" class="id_link">#</a></dt><dd><p>
287         Indicates no error. (SQLSTATE 00000)
288       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NOT-FOUND"><span class="term">100 (<code class="symbol">ECPG_NOT_FOUND</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NOT-FOUND" class="id_link">#</a></dt><dd><p>
289        This is a harmless condition indicating that the last command
290        retrieved or processed zero rows, or that you are at the end of
291        the cursor.  (SQLSTATE 02000)
292       </p><p>
293        When processing a cursor in a loop, you could use this code as
294        a way to detect when to abort the loop, like this:
295 </p><pre class="programlisting">
296 while (1)
297 {
298     EXEC SQL FETCH ... ;
299     if (sqlca.sqlcode == ECPG_NOT_FOUND)
300         break;
301 }
302 </pre><p>
303        But <code class="literal">WHENEVER NOT FOUND DO BREAK</code> effectively
304        does this internally, so there is usually no advantage in
305        writing this out explicitly.
306       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-OUT-OF-MEMORY"><span class="term">-12 (<code class="symbol">ECPG_OUT_OF_MEMORY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-OUT-OF-MEMORY" class="id_link">#</a></dt><dd><p>
307         Indicates that your virtual memory is exhausted.  The numeric
308         value is defined as <code class="literal">-ENOMEM</code>.  (SQLSTATE
309         YE001)
310       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-UNSUPPORTED"><span class="term">-200 (<code class="symbol">ECPG_UNSUPPORTED</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-UNSUPPORTED" class="id_link">#</a></dt><dd><p>
311        Indicates the preprocessor has generated something that the
312        library does not know about.  Perhaps you are running
313        incompatible versions of the preprocessor and the
314        library. (SQLSTATE YE002)
315       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TOO-MANY-ARGUMENTS"><span class="term">-201 (<code class="symbol">ECPG_TOO_MANY_ARGUMENTS</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TOO-MANY-ARGUMENTS" class="id_link">#</a></dt><dd><p>
316        This means that the command specified more host variables than
317        the command expected.  (SQLSTATE 07001 or 07002)
318       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TOO-FEW-ARGUMENTS"><span class="term">-202 (<code class="symbol">ECPG_TOO_FEW_ARGUMENTS</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TOO-FEW-ARGUMENTS" class="id_link">#</a></dt><dd><p>
319        This means that the command specified fewer host variables than
320        the command expected.  (SQLSTATE 07001 or 07002)
321       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TOO-MANY-MATCHES"><span class="term">-203 (<code class="symbol">ECPG_TOO_MANY_MATCHES</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TOO-MANY-MATCHES" class="id_link">#</a></dt><dd><p>
322        This means a query has returned multiple rows but the statement
323        was only prepared to store one result row (for example, because
324        the specified variables are not arrays).  (SQLSTATE 21000)
325       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INT-FORMAT"><span class="term">-204 (<code class="symbol">ECPG_INT_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INT-FORMAT" class="id_link">#</a></dt><dd><p>
326        The host variable is of type <code class="type">int</code> and the datum in
327        the database is of a different type and contains a value that
328        cannot be interpreted as an <code class="type">int</code>.  The library uses
329        <code class="function">strtol()</code> for this conversion.  (SQLSTATE
330        42804)
331       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-UINT-FORMAT"><span class="term">-205 (<code class="symbol">ECPG_UINT_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-UINT-FORMAT" class="id_link">#</a></dt><dd><p>
332        The host variable is of type <code class="type">unsigned int</code> and the
333        datum in the database is of a different type and contains a
334        value that cannot be interpreted as an <code class="type">unsigned
335        int</code>.  The library uses <code class="function">strtoul()</code>
336        for this conversion.  (SQLSTATE 42804)
337       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-FLOAT-FORMAT"><span class="term">-206 (<code class="symbol">ECPG_FLOAT_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-FLOAT-FORMAT" class="id_link">#</a></dt><dd><p>
338        The host variable is of type <code class="type">float</code> and the datum
339        in the database is of another type and contains a value that
340        cannot be interpreted as a <code class="type">float</code>.  The library
341        uses <code class="function">strtod()</code> for this conversion.
342        (SQLSTATE 42804)
343       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NUMERIC-FORMAT"><span class="term">-207 (<code class="symbol">ECPG_NUMERIC_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NUMERIC-FORMAT" class="id_link">#</a></dt><dd><p>
344        The host variable is of type <code class="type">numeric</code> and the datum
345        in the database is of another type and contains a value that
346        cannot be interpreted as a <code class="type">numeric</code> value.
347        (SQLSTATE 42804)
348       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INTERVAL-FORMAT"><span class="term">-208 (<code class="symbol">ECPG_INTERVAL_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INTERVAL-FORMAT" class="id_link">#</a></dt><dd><p>
349        The host variable is of type <code class="type">interval</code> and the datum
350        in the database is of another type and contains a value that
351        cannot be interpreted as an <code class="type">interval</code> value.
352        (SQLSTATE 42804)
353       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-DATE-FORMAT"><span class="term">-209 (<code class="symbol">ECPG_DATE_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-DATE-FORMAT" class="id_link">#</a></dt><dd><p>
354        The host variable is of type <code class="type">date</code> and the datum in
355        the database is of another type and contains a value that
356        cannot be interpreted as a <code class="type">date</code> value.
357        (SQLSTATE 42804)
358       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TIMESTAMP-FORMAT"><span class="term">-210 (<code class="symbol">ECPG_TIMESTAMP_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TIMESTAMP-FORMAT" class="id_link">#</a></dt><dd><p>
359        The host variable is of type <code class="type">timestamp</code> and the
360        datum in the database is of another type and contains a value
361        that cannot be interpreted as a <code class="type">timestamp</code> value.
362        (SQLSTATE 42804)
363       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-CONVERT-BOOL"><span class="term">-211 (<code class="symbol">ECPG_CONVERT_BOOL</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-CONVERT-BOOL" class="id_link">#</a></dt><dd><p>
364        This means the host variable is of type <code class="type">bool</code> and
365        the datum in the database is neither <code class="literal">'t'</code> nor
366        <code class="literal">'f'</code>.  (SQLSTATE 42804)
367       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-EMPTY"><span class="term">-212 (<code class="symbol">ECPG_EMPTY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-EMPTY" class="id_link">#</a></dt><dd><p>
368        The statement sent to the <span class="productname">PostgreSQL</span>
369        server was empty.  (This cannot normally happen in an embedded
370        SQL program, so it might point to an internal error.)  (SQLSTATE
371        YE002)
372       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-MISSING-INDICATOR"><span class="term">-213 (<code class="symbol">ECPG_MISSING_INDICATOR</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-MISSING-INDICATOR" class="id_link">#</a></dt><dd><p>
373        A null value was returned and no null indicator variable was
374        supplied.  (SQLSTATE 22002)
375       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NO-ARRAY"><span class="term">-214 (<code class="symbol">ECPG_NO_ARRAY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NO-ARRAY" class="id_link">#</a></dt><dd><p>
376        An ordinary variable was used in a place that requires an
377        array.  (SQLSTATE 42804)
378       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-DATA-NOT-ARRAY"><span class="term">-215 (<code class="symbol">ECPG_DATA_NOT_ARRAY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-DATA-NOT-ARRAY" class="id_link">#</a></dt><dd><p>
379        The database returned an ordinary variable in a place that
380        requires array value.  (SQLSTATE 42804)
381       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-ARRAY-INSERT"><span class="term">-216 (<code class="symbol">ECPG_ARRAY_INSERT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-ARRAY-INSERT" class="id_link">#</a></dt><dd><p>
382        The value could not be inserted into the array.  (SQLSTATE
383        42804)
384       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NO-CONN"><span class="term">-220 (<code class="symbol">ECPG_NO_CONN</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NO-CONN" class="id_link">#</a></dt><dd><p>
385        The program tried to access a connection that does not exist.
386        (SQLSTATE 08003)
387       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NOT-CONN"><span class="term">-221 (<code class="symbol">ECPG_NOT_CONN</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NOT-CONN" class="id_link">#</a></dt><dd><p>
388        The program tried to access a connection that does exist but is
389        not open.  (This is an internal error.)  (SQLSTATE YE002)
390       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INVALID-STMT"><span class="term">-230 (<code class="symbol">ECPG_INVALID_STMT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INVALID-STMT" class="id_link">#</a></dt><dd><p>
391        The statement you are trying to use has not been prepared.
392        (SQLSTATE 26000)
393       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INFORMIX-DUPLICATE-KEY"><span class="term">-239 (<code class="symbol">ECPG_INFORMIX_DUPLICATE_KEY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INFORMIX-DUPLICATE-KEY" class="id_link">#</a></dt><dd><p>
394        Duplicate key error, violation of unique constraint (Informix
395        compatibility mode).  (SQLSTATE 23505)
396       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-UNKNOWN-DESCRIPTOR"><span class="term">-240 (<code class="symbol">ECPG_UNKNOWN_DESCRIPTOR</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-UNKNOWN-DESCRIPTOR" class="id_link">#</a></dt><dd><p>
397        The descriptor specified was not found.  The statement you are
398        trying to use has not been prepared.  (SQLSTATE 33000)
399       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INVALID-DESCRIPTOR-INDEX"><span class="term">-241 (<code class="symbol">ECPG_INVALID_DESCRIPTOR_INDEX</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INVALID-DESCRIPTOR-INDEX" class="id_link">#</a></dt><dd><p>
400        The descriptor index specified was out of range.  (SQLSTATE
401        07009)
402       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-UNKNOWN-DESCRIPTOR-ITEM"><span class="term">-242 (<code class="symbol">ECPG_UNKNOWN_DESCRIPTOR_ITEM</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-UNKNOWN-DESCRIPTOR-ITEM" class="id_link">#</a></dt><dd><p>
403        An invalid descriptor item was requested.  (This is an internal
404        error.)  (SQLSTATE YE002)
405       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-VAR-NOT-NUMERIC"><span class="term">-243 (<code class="symbol">ECPG_VAR_NOT_NUMERIC</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-VAR-NOT-NUMERIC" class="id_link">#</a></dt><dd><p>
406        During the execution of a dynamic statement, the database
407        returned a numeric value and the host variable was not numeric.
408        (SQLSTATE 07006)
409       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-VAR-NOT-CHAR"><span class="term">-244 (<code class="symbol">ECPG_VAR_NOT_CHAR</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-VAR-NOT-CHAR" class="id_link">#</a></dt><dd><p>
410        During the execution of a dynamic statement, the database
411        returned a non-numeric value and the host variable was numeric.
412        (SQLSTATE 07006)
413       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INFORMIX-SUBSELECT-NOT-ONE"><span class="term">-284 (<code class="symbol">ECPG_INFORMIX_SUBSELECT_NOT_ONE</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INFORMIX-SUBSELECT-NOT-ONE" class="id_link">#</a></dt><dd><p>
414        A result of the subquery is not single row (Informix
415        compatibility mode).  (SQLSTATE 21000)
416       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-PGSQL"><span class="term">-400 (<code class="symbol">ECPG_PGSQL</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-PGSQL" class="id_link">#</a></dt><dd><p>
417        Some error caused by the <span class="productname">PostgreSQL</span>
418        server.  The message contains the error message from the
419        <span class="productname">PostgreSQL</span> server.
420       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TRANS"><span class="term">-401 (<code class="symbol">ECPG_TRANS</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TRANS" class="id_link">#</a></dt><dd><p>
421        The <span class="productname">PostgreSQL</span> server signaled that
422        we cannot start, commit, or rollback the transaction.
423        (SQLSTATE 08007)
424       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-CONNECT"><span class="term">-402 (<code class="symbol">ECPG_CONNECT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-CONNECT" class="id_link">#</a></dt><dd><p>
425        The connection attempt to the database did not succeed.
426        (SQLSTATE 08001)
427       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-DUPLICATE-KEY"><span class="term">-403 (<code class="symbol">ECPG_DUPLICATE_KEY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-DUPLICATE-KEY" class="id_link">#</a></dt><dd><p>
428        Duplicate key error, violation of unique constraint.  (SQLSTATE
429        23505)
430       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-SUBSELECT-NOT-ONE"><span class="term">-404 (<code class="symbol">ECPG_SUBSELECT_NOT_ONE</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-SUBSELECT-NOT-ONE" class="id_link">#</a></dt><dd><p>
431        A result for the subquery is not single row. (SQLSTATE 21000)
432       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-UNKNOWN-PORTAL"><span class="term">-602 (<code class="symbol">ECPG_WARNING_UNKNOWN_PORTAL</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-UNKNOWN-PORTAL" class="id_link">#</a></dt><dd><p>
433        An invalid cursor name was specified. (SQLSTATE 34000)
434       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-IN-TRANSACTION"><span class="term">-603 (<code class="symbol">ECPG_WARNING_IN_TRANSACTION</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-IN-TRANSACTION" class="id_link">#</a></dt><dd><p>
435        Transaction is in progress. (SQLSTATE 25001)
436       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-NO-TRANSACTION"><span class="term">-604 (<code class="symbol">ECPG_WARNING_NO_TRANSACTION</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-NO-TRANSACTION" class="id_link">#</a></dt><dd><p>
437        There is no active (in-progress) transaction. (SQLSTATE 25P01)
438       </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-PORTAL-EXISTS"><span class="term">-605 (<code class="symbol">ECPG_WARNING_PORTAL_EXISTS</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-PORTAL-EXISTS" class="id_link">#</a></dt><dd><p>
439        An existing cursor name was specified. (SQLSTATE 42P03)
440       </p></dd></dl></div><p>
441   </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ecpg-descriptors.html" title="34.7. Using Descriptor Areas">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ecpg.html" title="Chapter 34. ECPG — Embedded SQL in C">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ecpg-preproc.html" title="34.9. Preprocessor Directives">Next</a></td></tr><tr><td width="40%" align="left" valign="top">34.7. Using Descriptor Areas </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 34.9. Preprocessor Directives</td></tr></table></div></body></html>