This chapter contains several examples of pgtcl. Most of these are not self-contained programs, and in many cases error checking has been omitted for clarity.
This example shows how to connect to the database and get the server version string using pg_exec.
Note that pg_result ... -getTuple always returns a Tcl
list of values, even if only a single column of data is produced by the query.
To get the first (or only) column value, you must use
lindex.
Example 5.1. Connect to the database and get its version with pg_exec
set conn [pg_connect -conninfo "host=server.example.com dbname=template1 user=guest password=secret"] set result [pg_exec $conn "SELECT version()"] set value [lindex [pg_result $result -getTuple 0] 0] pg_result $result -clear puts "Server version is: $value" pg_disconnect $conn
This version of the manual was produced for the
Pgtcl-ng Sourceforge project web service site, which requires the logo on each
page.
To download a logo-free copy of the manual, see the
Pgtcl-ng project
downloads area.