PG_RESULT(n)
π PG_RESULT π
okay bestie, welcome to the PostgreSQL Tcl Interface Documentation glow-up for pg_result β the Tcl-side info-getter for command results. it's giving βlittle command, big energyβ and we're gonna go through every option together. π
πΈ NAME πΈ
pg_result β get information about a command result. periodt. π
β¨ SYNOPSIS β¨
pg_result resultHandle resultOption
π DESCRIPTION π
pg_result returns information about a command result created by a prior pg_exec. slay.
You can keep a command result around for as long as you need it, bestie β but when you're done with it, be sure to free it by executing pg_result -clear. Otherwise you have a memory leak, and pgtcl will eventually start complaining that you have created too many command result objects. π
bestie this is the βplease clean up your toysβ warning π§ β no cap, pg_result -clear matters.
π ARGUMENTS π
resultHandleβ the handle of the command result. iconic.resultOptionβ one of the following options, specifying which piece of result information to return:-statusβ the status of the result.-error [diagCode]β the error message, if the status indicates an error, otherwise an empty string. IfdiagCodeis specified, it requests data for a specific diagnostic code, like:severityβ the severity; the field contents areERROR,FATAL, orPANIC, in an error message, orWARNING,NOTICE,DEBUG,INFO, orLOG, in a notice message, or a localized translation of one of these.sqlstateβ the SQLSTATE code for the error. (See PostgreSQL manual Appendix A).primaryβ the primary human-readable error message (typically one line).detailβ an optional secondary error message carrying more detail about the problem, which may run to multiple lines.hintβ an optional suggestion about what to do about the problem. This is intended to differ fromdetailin that it offers advice (potentially inappropriate) rather than hard facts. The result may run to multiple lines.positionβ a string containing a decimal integer indicating an error cursor position as an index into the original statement string. The first character has index1, and positions are measured in characters not bytes.internal_positionβ this is the same asposition, but it is used when the cursor position refers to an internally generated command rather than the one submitted by the client. The first character has index1, and positions are measured in characters not bytes.internal_queryβ this is the text of a failed internally generated command. This could be, for example, a SQL query issued by a PL/pgSQL function.contextβ 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.fileβ the filename of the source code location where the error was reported.lineβ the line number of the source code location where the error was reported.functionβ the name of the source code function reporting the error.
-foreach arrayName tclCodeβ iterates through each row of the result, fillingarrayNamewith the columns and their values and executingtclCodefor each row in turn. Null columns will be not be present in the array.-connβ the connection that produced the result.-oidβ if the command was anINSERT, the OID of the inserted row, otherwise0.-numTuplesβ the number of rows (tuples) returned by the query.-cmdTuplesβ the number of rows (tuples) affected by the command. (This is similar to-numTuplesbut relevant toINSERTandUPDATEcommands.)-numAttrsβ the number of columns (attributes) in each row.-assign arrayNameβ assign the results to an array, using subscripts of the form(rowNumber, columnName).-foreach arrayName codeβ for each resulting row assigns the results to the named array, using subscripts matching the column names, then executes the code body. (yes bestie,-foreachis listed again here withcodeinstead oftclCodeβ keeping both entries exactly as the page gives them. π )-assignbyidx arrayName [appendstr]β assign the results to an array using the values of the first column and the names of the remaining column as keys. Ifappendstris 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(firstColumnValue, columnNameAppendStr).-getTuple rowNumberβ returns the columns of the indicated row in a list. Row numbers start at zero.-tupleArray rowNumber arrayNameβ stores the columns of the row in arrayarrayName, 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.-tupleArrayWithoutNulls rowNumber arrayNameβ stores the columns of the row in arrayarrayName, indexed by column names. Row numbers start at zero. If a field's value is null, unsets the column from the array.-attributesβ returns a list of the names of the columns in the result.-lAttributesβ returns a list of sublists,{name typeOid typeSize}for each column.-listβ returns one list containing all the data returned by the query.-llistβ returns a list of lists, where each embedded list represents a tuple in the result.-dictβ 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-DHAVE_TCL_NEWDICTOBJto the Makefile in theDEFSvariable.-null_value_string [string]β defines or retrieves the string that will be returned for null values in query results. Defaults to whatever was set bypg_null_value_stringbut can be set here and, in this case, affects only this query result.-clearβ clear the command result object.
π«Ά RETURN VALUE π«Ά
The result depends on the selected option, as described above. iykyk. π
okay that's the whole manual page, bestie π«Ά β the PostgreSQL Tcl Interface Documentation energy for PG_RESULT(), dated 17 September 2020. mwah π
π¦ where this page comes from
- alpine 3.22: pgtcl-doc 3.1.0-r0 Β· BSD-3-Clause
- alpine 3.23: pgtcl-doc 3.1.1-r0 Β· BSD-3-Clause
- alpine 3.24: pgtcl-doc 3.1.1-r0 Β· BSD-3-Clause
- nixpkgs unstable: pgtcl 3.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms