| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 2 | "http://www.w3.org/TR/html4/loose.dtd"> |
| 3 | <html> |
| 4 | <head> |
| 5 | <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.6.0"> |
| 6 | <title>pg_result</title> |
| 7 | <meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.79"> |
| 8 | <link rev="MADE" href="mailto:[email protected]"> |
| 9 | <link rel="HOME" title="PostgreSQL Tcl Interface Documentation" href="index.html"> |
| 10 | <link rel="UP" title="pgtcl Command Reference" href="libpgtcl-ref.html"> |
| 11 | <link rel="PREVIOUS" title="pg_exec_prepared" href="pgtcl-pgexecprepared.html"> |
| 12 | <link rel="NEXT" title="pg_select" href="pgtcl-pgselect.html"> |
| 13 | <link rel="STYLESHEET" type="text/css" href="stylesheet.css"> |
| 14 | </head> |
| 15 | <body class="REFENTRY"> |
| 16 | <div class="NAVHEADER"> |
| 17 | <table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"> |
| 18 | <tr> |
| 19 | <th colspan="5" align="center" valign="bottom">PostgreSQL Tcl Interface Documentation</th> |
| 20 | </tr> |
| 21 | <tr> |
| 22 | <td width="10%" align="left" valign="top"><a href="pgtcl-pgexecprepared.html" accesskey="P">Prev</a></td> |
| 23 | <td width="10%" align="left" valign="top"><a href="pgtcl-pgexecprepared.html">Fast Backward</a></td> |
| 24 | <td width="60%" align="center" valign="bottom"></td> |
| 25 | <td width="10%" align="right" valign="top"><a href="pgtcl-pgselect.html">Fast Forward</a></td> |
| 26 | <td width="10%" align="right" valign="top"><a href="pgtcl-pgselect.html" accesskey="N">Next</a></td> |
| 27 | </tr> |
| 28 | </table> |
| 29 | <hr align="left" width="100%"></div> |
| 30 | <h1><a name="PGTCL-PGRESULT" id="PGTCL-PGRESULT"></a>pg_result</h1> |
| 31 | <div class="REFNAMEDIV"><a name="AEN907" id="AEN907"></a> |
| 32 | <h2>Name</h2> |
| 33 | pg_result -- get information about a command result<a name="IX-PGTCL-PGRESULT-2" id="IX-PGTCL-PGRESULT-2"></a></div> |
| 34 | <div class="REFSYNOPSISDIV"><a name="AEN912" id="AEN912"></a> |
| 35 | <h2>Synopsis</h2> |
| 36 | <pre class="SYNOPSIS">pg_result <code class="PARAMETER">resultHandle</code> <code class="PARAMETER">resultOption</code></pre></div> |
| 37 | <div class="REFSECT1"><a name="AEN916" id="AEN916"></a> |
| 38 | <h2>Description</h2> |
| 39 | <p><code class="FUNCTION">pg_result</code> returns information about a command result created by a prior <code class="FUNCTION">pg_exec</code>.</p> |
| 40 | <p>You can keep a command result around for as long as you need it, but when you are done with it, be sure to free it by executing <code class="FUNCTION">pg_result -clear</code>. Otherwise, you have a memory leak, and <span class="APPLICATION">pgtcl</span> will eventually start complaining that you have created too many command result objects.</p> |
| 41 | </div> |
| 42 | <div class="REFSECT1"><a name="AEN924" id="AEN924"></a> |
| 43 | <h2>Arguments</h2> |
| 44 | <div class="VARIABLELIST"> |
| 45 | <dl> |
| 46 | <dt><code class="PARAMETER">resultHandle</code></dt> |
| 47 | <dd> |
| 48 | <p>The handle of the command result.</p> |
| 49 | </dd> |
| 50 | <dt><code class="PARAMETER">resultOption</code></dt> |
| 51 | <dd> |
| 52 | <p>One of the following options, specifying which piece of result information to return:</p> |
| 53 | <div class="VARIABLELIST"> |
| 54 | <dl> |
| 55 | <dt><code class="OPTION">-status</code></dt> |
| 56 | <dd> |
| 57 | <p>The status of the result.</p> |
| 58 | </dd> |
| 59 | <dt><code class="OPTION">-error</code> ?<span class="OPTIONAL"><code class="PARAMETER">diagCode</code></span>?</dt> |
| 60 | <dd> |
| 61 | <p>The error message, if the status indicates an error, otherwise an empty string.</p> |
| 62 | <p><code class="PARAMETER">diagCode</code>, if specified, requests data for a specific diagnostic code:</p> |
| 63 | <div class="VARIABLELIST"> |
| 64 | <dl> |
| 65 | <dt><code class="OPTION">severity</code></dt> |
| 66 | <dd> |
| 67 | <p>The severity; the field contents are <tt class="LITERAL">ERROR</tt>, <tt class="LITERAL">FATAL</tt>, or <tt class="LITERAL">PANIC</tt>, in an error message, or <tt class="LITERAL">WARNING</tt>, <tt class="LITERAL">NOTICE</tt>, <tt class="LITERAL">DEBUG</tt>, <tt class="LITERAL">INFO</tt>, or <tt class="LITERAL">LOG</tt>, in a notice message, or a localized translation of one of these.</p> |
| 68 | </dd> |
| 69 | <dt><code class="OPTION">sqlstate</code></dt> |
| 70 | <dd> |
| 71 | <p>The <tt class="LITERAL">SQLSTATE</tt> code for the error. (See <span class="PRODUCTNAME">PostgreSQL</span> manual Appendix A).</p> |
| 72 | </dd> |
| 73 | <dt><code class="OPTION">primary</code></dt> |
| 74 | <dd> |
| 75 | <p>The primary human-readable error message (typically one line).</p> |
| 76 | </dd> |
| 77 | <dt><code class="OPTION">detail</code></dt> |
| 78 | <dd> |
| 79 | <p>An optional secondary error message carrying more detail abhout the problem, which may run to multiple lines.</p> |
| 80 | </dd> |
| 81 | <dt><code class="OPTION">hint</code></dt> |
| 82 | <dd> |
| 83 | <p>An optional suggestion about what to do about the problem. This is intended to differ from detail in that it offers advice (potentially inappropriate) rather than hard facts.</p> |
| 84 | <p>The result may run to multiple lines.</p> |
| 85 | </dd> |
| 86 | <dt><code class="OPTION">position</code></dt> |
| 87 | <dd> |
| 88 | <p>A string containing a decimal integer indicating an error cursor position as an index into the original statement string.</p> |
| 89 | <p>The first character has index <tt class="LITERAL">1</tt>, and positions are measured in characters not bytes.</p> |
| 90 | </dd> |
| 91 | <dt><code class="OPTION">internal_position</code></dt> |
| 92 | <dd> |
| 93 | <p>This is the same as "position", but it is used when the cursor position refers to an internally generated command rather than the one submitted by the client.</p> |
| 94 | <p>The first character has index <tt class="LITERAL">1</tt>, and positions are measured in characters not bytes.</p> |
| 95 | </dd> |
| 96 | <dt><code class="OPTION">internal_query</code></dt> |
| 97 | <dd> |
| 98 | <p>This is the text of a failed internally generated command. This could be, for example, a SQL query issued by a PL/pgSQL function.</p> |
| 99 | </dd> |
| 100 | <dt><code class="OPTION">context</code></dt> |
| 101 | <dd> |
| 102 | <p>An indication of the context in which the error occurred. Presently this includes a call stack traceback of active PL functions. The trace is one entry per line, most recent first.</p> |
| 103 | </dd> |
| 104 | <dt><code class="OPTION">file</code></dt> |
| 105 | <dd> |
| 106 | <p>The filename of the source code location where the error was reported.</p> |
| 107 | </dd> |
| 108 | <dt><code class="OPTION">line</code></dt> |
| 109 | <dd> |
| 110 | <p>The line number of the source code location where the error was reported.</p> |
| 111 | </dd> |
| 112 | <dt><code class="OPTION">function</code></dt> |
| 113 | <dd> |
| 114 | <p>The name of the source code function reporting the error.</p> |
| 115 | </dd> |
| 116 | </dl> |
| 117 | </div> |
| 118 | </dd> |
| 119 | <dt><code class="OPTION">-foreach <code class="PARAMETER">arrayName</code> <code class="PARAMETER">tclCode</code></code></dt> |
| 120 | <dd> |
| 121 | <p>Iterates through each row of the result, filling <code class="PARAMETER">arrayName</code> with the columns and their values and executing <code class="PARAMETER">tclCode</code> for each row in turn. Null columns will be not be present in the array.</p> |
| 122 | </dd> |
| 123 | <dt><code class="OPTION">-conn</code></dt> |
| 124 | <dd> |
| 125 | <p>The connection that produced the result.</p> |
| 126 | </dd> |
| 127 | <dt><code class="OPTION">-oid</code></dt> |
| 128 | <dd> |
| 129 | <p>If the command was an <tt class="COMMAND">INSERT</tt>, the OID of the inserted row, otherwise 0.</p> |
| 130 | </dd> |
| 131 | <dt><code class="OPTION">-numTuples</code></dt> |
| 132 | <dd> |
| 133 | <p>The number of rows (tuples) returned by the query.</p> |
| 134 | </dd> |
| 135 | <dt><code class="OPTION">-cmdTuples</code></dt> |
| 136 | <dd> |
| 137 | <p>The number of rows (tuples) affected by the command. (This is similar to <code class="OPTION">-numTuples</code> but relevant to <tt class="COMMAND">INSERT</tt> and <tt class="COMMAND">UPDATE</tt> commands.)</p> |
| 138 | </dd> |
| 139 | <dt><code class="OPTION">-numAttrs</code></dt> |
| 140 | <dd> |
| 141 | <p>The number of columns (attributes) in each row.</p> |
| 142 | </dd> |
| 143 | <dt><code class="OPTION">-assign <code class="PARAMETER">arrayName</code></code></dt> |
| 144 | <dd> |
| 145 | <p>Assign the results to an array, using subscripts of the form <tt class="LITERAL">(rowNumber, columnName)</tt>.</p> |
| 146 | </dd> |
| 147 | <dt><code class="OPTION">-foreach <code class="PARAMETER">arrayName</code> <code class="PARAMETER">code</code></code></dt> |
| 148 | <dd> |
| 149 | <p>For each resulting row assigns the results to the named array, using subscripts matching the column names, then executes the code body.</p> |
| 150 | </dd> |
| 151 | <dt><code class="OPTION">-assignbyidx <code class="PARAMETER">arrayName</code> ?<span class="OPTIONAL"><code class="PARAMETER">appendstr</code></span>?</code></dt> |
| 152 | <dd> |
| 153 | <p>Assign the results to an array using the values of the first column and the names of the remaining column as keys. If <code class="PARAMETER">appendstr</code> is given then it is appended to each key. In short, all but the first column of each row are stored into the array, using subscripts of the form <tt class="LITERAL">(firstColumnValue, columnNameAppendStr)</tt>.</p> |
| 154 | </dd> |
| 155 | <dt><code class="OPTION">-getTuple <code class="PARAMETER">rowNumber</code></code></dt> |
| 156 | <dd> |
| 157 | <p>Returns the columns of the indicated row in a list. Row numbers start at zero.</p> |
| 158 | </dd> |
| 159 | <dt><code class="OPTION">-tupleArray <code class="PARAMETER">rowNumber</code> <code class="PARAMETER">arrayName</code></code></dt> |
| 160 | <dd> |
| 161 | <p>Stores the columns of the row in array <code class="PARAMETER">arrayName</code>, indexed by column names. Row numbers start at zero. If a field's value is null, sets an empty string or the default string, if a default string has been defined.</p> |
| 162 | </dd> |
| 163 | <dt><code class="OPTION">-tupleArrayWithoutNulls <code class="PARAMETER">rowNumber</code> <code class="PARAMETER">arrayName</code></code></dt> |
| 164 | <dd> |
| 165 | <p>Stores the columns of the row in array <code class="PARAMETER">arrayName</code>, indexed by column names. Row numbers start at zero. If a field's value is null, unsets the column from the array.</p> |
| 166 | </dd> |
| 167 | <dt><code class="OPTION">-attributes</code></dt> |
| 168 | <dd> |
| 169 | <p>Returns a list of the names of the columns in the result.</p> |
| 170 | </dd> |
| 171 | <dt><code class="OPTION">-lAttributes</code></dt> |
| 172 | <dd> |
| 173 | <p>Returns a list of sublists, <tt class="LITERAL">{name typeOid typeSize}</tt> for each column.</p> |
| 174 | </dd> |
| 175 | <dt><code class="OPTION">-list</code></dt> |
| 176 | <dd> |
| 177 | <p>Returns one list containing all the data returned by the query.</p> |
| 178 | </dd> |
| 179 | <dt><code class="OPTION">-llist</code></dt> |
| 180 | <dd> |
| 181 | <p>Returns a list of lists, where each embedded list represents a tuple in the result.</p> |
| 182 | </dd> |
| 183 | <dt><code class="OPTION">-dict</code></dt> |
| 184 | <dd> |
| 185 | <p>Returns a dict object with the results. This needs to have dictionary support built into Tcl (Tcl 8.5), and is experimental right now, since Tcl 8.5 has not been release yet, and the API could change. In order to enable this, you need to add <tt class="LITERAL">-DHAVE_TCL_NEWDICTOBJ</tt> to the Makefile in the <tt class="LITERAL">DEFS</tt> variable.</p> |
| 186 | </dd> |
| 187 | <dt><code class="OPTION">-null_value_string ?<span class="OPTIONAL"><code class="PARAMETER">string</code></span>?</code></dt> |
| 188 | <dd> |
| 189 | <p>Defines or retrieves the string that will be returned for null values in query results. Defaults to whatever was set by <code class="FUNCTION">pg_null_value_string</code> but can be set here and, in this case, affects only this query result.</p> |
| 190 | </dd> |
| 191 | <dt><code class="OPTION">-clear</code></dt> |
| 192 | <dd> |
| 193 | <p>Clear the command result object.</p> |
| 194 | </dd> |
| 195 | </dl> |
| 196 | </div> |
| 197 | </dd> |
| 198 | </dl> |
| 199 | </div> |
| 200 | </div> |
| 201 | <div class="REFSECT1"><a name="AEN1153" id="AEN1153"></a> |
| 202 | <h2>Return Value</h2> |
| 203 | <p>The result depends on the selected option, as described above.</p> |
| 204 | </div> |
| 205 | <div class="NAVFOOTER"> |
| 206 | <hr align="left" width="100%"> |
| 207 | <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"> |
| 208 | <tr> |
| 209 | <td width="33%" align="left" valign="top"><a href="pgtcl-pgexecprepared.html" accesskey="P">Prev</a></td> |
| 210 | <td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">Home</a></td> |
| 211 | <td width="33%" align="right" valign="top"><a href="pgtcl-pgselect.html" accesskey="N">Next</a></td> |
| 212 | </tr> |
| 213 | <tr> |
| 214 | <td width="33%" align="left" valign="top">pg_exec_prepared</td> |
| 215 | <td width="34%" align="center" valign="top"><a href="libpgtcl-ref.html" accesskey="U">Up</a></td> |
| 216 | <td width="33%" align="right" valign="top">pg_select</td> |
| 217 | </tr> |
| 218 | </table> |
| 219 | </div> |
| 220 | </body> |
| 221 | </html> |