pgtcl Command Reference Information

pg_connect

pg_connect opens a connection to the backend server. A single option string is supplied that can contain multiple option values.
pg_connect -conninfo connectOptions
Returns a connection options array.

Example

pg_connect -conninfo "dbname=pcheung port=5432 host=localhost"

pg_disconnect

pg_disconnect closes a connection to the backend server.
pg_disconnect dbHandle

Example

pg_disconnect pgsql3

pg_conndefaults

pg_conndefaults returns information about thr default connection options available in
pg_connect -conninfo
and the current default value for each option.

pg_conndefaults

Example

pg_conndefaults

pg_exec

pg_exec submits a query to the PostgreSQL backend and returns a result. Query result handles start with the connection handle and add a period and a result number.

pg_exec dbHandle queryString

An error message returned by the backend will be processed as a query result with failure status, not by generating a Tcl error in pg_exec. Hence, the absence of a Tcl error does not necessarily mean the query completed successfully.

Example

pg_exec $conn "SELECT * from table_a"

pg_result

pg_result returns information about a query result created by a prior pg_exec.

pg_result resultHandle resultOption

Example

set res [pg_exec $conn "SELECT * from table_a"]
puts [pg_result $res -status]
puts [pg_result $res -numTuples]
puts [pg_result $res -getTuple 0]
pg_result $res -clear

pg_select

pg_select loops over the result of a SELECT statement.
pg_select dbHandle queryString arrayVar queryProcedure

pg_listen

pg_listen sets or changes a callback for asynchronous NOTIFY messages.
pg_listen dbHandle notifyName callbackCommand

pg_lo_creat

pg_lo_creat creates an Inversion Large Object.
pg_lo_creat conn mode

Example

pg_exec $conn "BEGIN"
pg_lo_creat $conn "INV_READ|INV_WRITE"
pg_exec $conn "END"

pg_lo_open

pg_lo_open opens an Inversion Large Object.
pg_lo_open conn objOid mode

Example

pg_exec $conn "BEGIN"
set fd [pg_lo_open $conn $loid r]
pg_exec $conn "END"

pg_lo_close

pg_lo_close closes an Inversion Large Object.
pg_lo_close conn fd

Example

pg_exec $conn "BEGIN"
set fd [pg_lo_open $conn $loid r]
pg_lo_close $conn $fd
pg_exec $conn "END"

pg_lo_read

pg_lo_read reads at most len bytes from a large object into a variable named bufVar.
pg_lo_read conn fd bufVar len

Example

pg_exec $conn "BEGIN"
set fd [pg_lo_open $conn $loid r]
pg_lo_read $conn $fd var 128
puts $var
pg_exec $conn "END"

pg_lo_write

pg_lo_write writes at most len bytes to a large object from a variable buf.
pg_lo_write conn fd buf len

Example

pg_exec $conn "BEGIN"
set fd [pg_lo_open $conn $loid r]
pg_lo_write $conn $fd "abc" 3
pg_exec $conn "END"

pg_lo_lseek

pg_lo_lseek positions to offset bytes from the beginning of a large object.
pg_lo_lseek conn fd offset whence

Example

pg_exec $conn "BEGIN"
set fd [pg_lo_open $conn $loid r]
use pg_lo_seek $conn $fd 0 SEEK_SET
pg_exec $conn "END"

pg_lo_tell

pg_lo_tell returns the current to offset in bytes from the beginning of a large object.
pg_lo_tell conn fd

Example

pg_exec $conn "BEGIN"
set fd [pg_lo_open $conn $loid r]
pg_lo_read $conn $fd var 128
puts $var
pg_lo_tell $conn $fd
pg_exec $conn "END"

pg_lo_unlink

pg_lo_unlink deletes the specified large object.
pg_lo_unlink conn lobjId

Example

pg_exec $conn "BEGIN"
set loid[pg_lo_create $conn "INV_REAP"]
pg_lo_unlink $conn $loid
pg_exec $conn "END"

pg_lo_import

pg_lo_import reads the specified file and places the contents into a large object.
pg_lo_import conn filename

Example

pg_lo_import must be called within a BEGIN/END transaction block.

pg_exec $conn "BEGIN"
pg_lo_import $conn /tmp/file1
pg_exec $conn "END"

pg_lo_export

pg_lo_export writes the specified large object into a Linux file.
pg_lo_export conn lobjId filename
Exports a large object to a Linux file.

Example

pg_lo_export must be called within a BEGIN/END transaction block.

pg_exec $conn "BEGIN"
set loid[pg_lo_import $conn /tmp/file1]
pg_lo_export $conn $loid /tmp/file2
pg_exec $conn "END"