Database Reference
In-Depth Information
The result can be seen using the following statement:
warehouse_db=# SELECT how_to_raise();
NOTICE: Table is empty. Currently, 0, row
ERROR: Transaction will be aborted
Native support for other procedural
languages
PL/pgSQL is not the only procedural language available for PostgreSQL. It has
native support for Python, Perl and Tcl as well. It doesn't stop here. However, it
allows the usage of other procedural languages, for example, PL/Java and PL/Ruby.
PostgreSQL uses bison (a parser generator) in the parsing process, thus enabling it to
allow support for various open source languages.
In this section, we will skim through the usage of PostgreSQL native procedural
languages such as PL/Python, PL/Perl, and PL/Tcl. We will learn how to write
basic functions in these languages, pass arguments, and access a database.
Earlier, you saw that a language must irst be installed to make it work. If you recall,
the createlang shell script was used earlier to install PL/pgSQL. Now, you can also
use the CREATE EXTENSION database_name query to install the other procedural
languages.
Do check the installation notes for your PostgreSQL installation to
see which version of Python, Perl, and Tcl are compiled with the
PostgreSQL version you are using. After installing the packages,
make sure that they are added to system's PATH variable as well.
PL/Python
PL/Python is a procedural language that helps write stored functions in Python.
Installing PL/Python
The installation of PL/Python is fairly simple; launch the psql utility, connect to the
warehouse_db database (created earlier), and execute the following command:
$ ./psql -U postgres -d warehouse_db
We can create an extension for Python using the following statement:
warehouse_db=# CREATE EXTENSION plpython3u;
 
Search WWH ::




Custom Search