1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
10 HREF="mailto:pgsql-docs@postgresql.org"><LINK
12 TITLE="PostgreSQL 7.4.1 Documentation"
13 HREF="index.html"><LINK
15 TITLE="pgtcl Command Reference"
16 HREF="libpgtcl-ref.html"><LINK
19 HREF="pgtcl-pgselect.html"><LINK
22 HREF="pgtcl-pglisten.html"><LINK
25 HREF="stylesheet.css"><META
27 CONTENT="2003-12-22T03:48:47"></HEAD
33 SUMMARY="Header navigation table"
43 >PostgreSQL 7.4.1 Documentation</TH
51 HREF="pgtcl-pgselect.html"
60 HREF="pgtcl-pgselect.html"
73 HREF="pgtcl-pglisten.html"
81 HREF="pgtcl-pglisten.html"
92 NAME="PGTCL-PGEXECUTE"
102 >pg_execute -- send a query and optionally loop over the results<A
103 NAME="IX-PGTCL-PGEXECUTE-2"
107 CLASS="REFSYNOPSISDIV"
152 > submits a command to the
159 > If the command is not a <TT
163 number of rows affected by the command is returned. If the command
167 > statement and a single row is
168 inserted, the OID of the inserted row is stored in the variable
172 > if the optional <VAR
176 argument is supplied.
179 > If the command is a <TT
182 > statement, then, for
183 each row in the result, the row values are stored in the
187 > variable, if supplied, using the
188 column names as the array indices, else in variables named by the
189 column names, and then the optional
193 > is executed if supplied.
197 > probably makes sense
198 only if the query will return a single row.) The number of rows
199 selected is returned.
205 > can use the Tcl commands
216 > with the expected behavior. Note that if
228 does not return the number of affected rows.
234 > is a newer function which provides
235 a superset of the features of <CODE
242 > in many cases where access
243 to the result handle is not needed.
246 > For server-handled errors, <CODE
250 throw a Tcl error and return a two-element list. The first element
251 is an error code, such as <TT
253 >PGRES_FATAL_ERROR</TT
255 the second element is the server error text. For more serious
256 errors, such as failure to communicate with the server,
260 > will throw a Tcl error and return
261 just the error message text.
286 > Specifies the name of an array variable where result rows are
287 stored, indexed by the column names. This is ignored if
308 > Specifies the name of a variable into which the OID from an
312 > statement will be stored.
322 > The handle of the connection on which to execute the command.
332 > The SQL command to execute.
342 > Optional procedure to execute for each result row of a
360 > The number of rows affected or returned by the command.
371 > In the following examples, error checking with
375 > has been omitted for clarity.
378 > Insert a row and save the OID in <VAR
383 CLASS="PROGRAMLISTING"
384 >pg_execute -oid result_oid $pgconn "INSERT INTO mytable VALUES (1);"</PRE
388 > Print the columns <TT
397 CLASS="PROGRAMLISTING"
398 >pg_execute -array d $pgconn "SELECT item, value FROM mytable;" {
399 puts "Item=$d(item) Value=$d(value)"
404 > Find the maximum and minimum values and store them in
413 CLASS="PROGRAMLISTING"
414 >pg_execute -array s $pgconn "SELECT max(value) AS max, min(value) AS min FROM mytable;"</PRE
418 > Find the maximum and minimum values and store them in
427 CLASS="PROGRAMLISTING"
428 >pg_execute $pgconn "SELECT max(value) AS max, min(value) AS min FROM mytable;"</PRE
437 SUMMARY="Footer navigation table"
448 HREF="pgtcl-pgselect.html"
466 HREF="pgtcl-pglisten.html"
482 HREF="libpgtcl-ref.html"