In the previous chapters, we discussed PL/pgSQL which is one of the standard procedural languages distributed with PostgreSQL. PL/pgSQL is a language unique to PostgreSQL and was designed to add blocks of computation and SQL inside the database. While it has grown in its breadth of functionality, it still lacks the completeness of syntax of a full programming language. PL/Python allows your database functions to be written in Python with all the depth and maturity of writing a Python code outside the database.
Let's start from the very beginning, yet again:
CREATE FUNCTION hello(name text) RETURNS text AS $$ return 'hello %s !' % name $$ LANGUAGE plpythonu;
Here, we see that creating a function starts by defining it as any other PostgreSQL function with a RETURNS
definition of a text
field:
CREATE FUNCTION hello(name text) RETURNS text
The difference from what we have seen before, is that the language part is specifying plpythonu...