If you want to try the examples in this chapter, you will need to install and configure Tcl/Tk (version 8.0 or later) and libpgtcl.

If you are running on a Linux host, the chances are good that you already have Tcl/Tk installed on your system. To find out whether Tcl is ready to use, enter the command tclsh, as shown here:

$ tclsh

%  exit


If you see the % prompt, you have Tcl installed on your system. If instead, you see an error such as "tcl: command not found", you may still have a copy of Tcl installed on your system, but it's not in your search path ($PATH) ?ask your system administrator whether Tcl is available.

If you find that you need to install Tcl, you can find it at ActiveState distributes Tcl/Tk in binary (precompiled) form for Linux, Solaris, and Windows. You can also find the source code for Tcl/Tk at ActiveState.

The second component that you need is libpgtcl. libpgtcl is a package of Tcl extension functions that enable a Tcl script to interact with PostgreSQL. This component can be a little hard to find. If you are building your copy of PostgreSQL from source code, adding the --with-tcl flag to configure should build libpgtcl for you. If you have installed PostgreSQL using a RPM package, be sure to install the postgresql-tcl package. If you are using Tcl on a Windows host, the easiest way to obtain the libpgtcl library is to install PgAccess (

Finally, some of the examples in this chapter require the TkTable extension to Tk. TkTable provides a table widget that you will use to display query results. If you have already installed Tcl and Tk, you may find that TkTable came with the distribution that you loaded. If not, you can find TkTable at

PostgreSQL-Related Tcl/Tk Components

As I mentioned in the previous section, libpgtcl is a library of PostgreSQL-related functions that you can call from within a Tcl script. The libpgtcl package also includes two shell programs. pgtclsh is a copy of the Tcl shell (tclsh) that automatically loads the libpgtcl library. pgtksh is a copy of the wish shell that will automatically load libpgtcl at startup.

    Part II: Programming with PostgreSQL