Chapter 12. PL/Tcl – Tcl Procedural Language

Tools Command Language (Tcl), also commonly known as tickle, has been around for a long time. It was created by John Ousterhout in 1988 and got a lot of traction for rapid prototyping and scripted applications.

In this chapter, we will take a brief look at PL/Tcl. Between PL/Perl, PL/Python, and PL/pgSQL, you have very powerful languages available at your disposal that can do almost anything you need. For some other things, you have the option to write your functions in C. You might wonder why it is useful to discuss PL/Tcl. For a long time, in the early days of PostgreSQL, PL/Tclu (untrusted PL/Tcl) was the only way to do things outside PostgreSQL, such as interacting with the operating system. A lot of people still use it, and I personally think that it is so clean and powerful that it should not be overlooked.

PL/Tcl is available as a trusted and an untrusted language. This is achieved by providing two different Tcl interpreters. PL/Tclu uses the standard Tcl interpreter, while PL/Tcl uses a special Safe Tcl mechanism.

Note

You can read more about safe Tcl at http://www.tcl.tk/software/plugin/safetcl.html.

In this chapter, we will cover the following topics:

  • Installing PL/Tcl and writing a simple function
  • Passing simple and complex parameters
  • Accessing a database from a Pl/Tcl function
  • Writing database triggers using Pl/Tcl

Installing PL/Tcl

PL/Tcl is not installed by default, if you've used the standard source distribution to install PostgreSQL. If you compiled PostgreSQL from the source, you need to run the configure script with the –-with-tcl option.

If you've used a binary distribution on your platform, you can normally install PL/Tcl using your package manager. You can search for postgresql-pltcl, or a similar package name, as it differs across distributions. Once PostgreSQL is compiled with the correct option, or you have installed the appropriate package, you can create the language using the createlang utility or the CREATE LANGUAGE command:

$ createlang pltcl template1

You can use also use the untrusted version to create the language, as follows:

$ createlang pltclu template1
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.37.56