PL/pgSQL
PL/pgSQL (Procedural Language/PostgreSQL) is a procedural programming language supported by the PostgreSQL ORDBMS. It closely resembles Oracle's PL/SQL language. Implemented by Jan Wieck, PL/pgSQL first appeared with PostgreSQL 6.4, released on October 30, 1998.[1] Version 9 also implements some ISO SQL/PSM features, like overloading of SQL-invoked functions and procedures.[2] PL/pgSQL, as a fully featured programming language, allows much more procedural control than SQL, including the ability to use loops and other control structures. SQL statements and triggers can call functions created in the PL/pgSQL language. The design of PL/pgSQL aimed to allow PostgreSQL users to perform more complex operations and computations than SQL, while providing ease of use. The language is able to be defined as trusted by the server.[3] PL/pgSQL is one of the programming languages included in the standard PostgreSQL distribution,[4] the others being PL/Tcl, PL/Perl[5] and PL/Python.[6] In addition, many others are available from third parties, including PL/Java,[7] PL/pgPSM,[8] PL/php,[9] PL/R,[10] PL/Ruby,[11] PL/sh, PL/Lua, Postmodern[12] (based on Common Lisp) and PL/v8. PostgreSQL uses Bison as its parser,[13] making it easy to port many open-source languages, as well as to reuse code. Comparing with PSMThe SQL/PSM language is specified by an ISO standard, but is also inspired by Oracle's PL/SQL and PL/pgPL/SQL, so there are few differences. The PL/pgPSM contributed module implements the standard. The main features of PSM that differ from PL/pgSQL:[8][14]
All three languages (Oracle PL/SQL,[15] PostgreSQL PL/pgSQL and ISO SQL/PSM[16]) are originally descended from the Ada programming language. ExampleCREATE FUNCTION sales_tax(subtotal real) RETURNS real AS $$
BEGIN
RETURN subtotal * 0.06;
END;
$$ LANGUAGE plpgsql;
Inline documentation external supportFormal pseudo-language for documentation can be embedded in SQL and PL/pgSQL scripts. This documentation is then processed by a documentation generator—an external tool which extracts data and generates hypertext. Since PL/SQL: supports some of these tools, PL/pgSQL is expected to provide full or partial support as well.
Other documentation tools: Doxygen, DBScribe, HyperSQL, Universal Report. References
External links
|