Jump to content

PL/pgSQL

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 187.90.157.126 (talk) at 13:29, 10 December 2014 (refs. format, details). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

PL/pgSQL (Procedural Language/PostgreSQL) is a procedural programming language supported by the PostgreSQL ORDBMS. It closely resembles Oracle's PL/SQL language. Released with v7 in 2000[1], with PostgreSQL v9 some ISO SQL/PSM features, like overloading of SQL-invoked functions and procedures,[2] are supported.

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. Functions created in the PL/pgSQL language can be called from an SQL statement, or as the action that a trigger performs.

PL/pgSQL was created to be able to perform more complex operations and computations than SQL, while being easy to use, and is able to be defined as trusted by the server.[3]

PL/pgSQL is the only programming language installed by default for PostgreSQL, but many others are available, including PL/Java[4], PL/Perl[5], PL/php, PL/Python, PL/R, PL/Ruby, PL/sh, PL/Tcl, and PL/Lua. PostgreSQL uses Bison as its parser,[6] so it is easy to port many open source languages, as well as reuse code.

Comparing with PSM

The SQL/PSM language is specified by an ISO standard, but also inspired by Oracle's PL/SQL and pgPL/SQL, so there are few differences. The main features of PSM that differ from PL/pgSQL:[7]

  • Exception handlers are subroutines (continue handlers);
  • Warnings can be handled like an exception;
  • Declaration of variables should be based on SQL query result.

References

  1. ^ Cunningham, Lewis (2011), "1. Introduction to EnterpriseDB: A Mini-History of PostgreSQL", EnterpriseDB, The Definitive Reference: The Oracle-Compatible Enterprise database, Databases IT In-Focus Series, ISBN 0-9776715-7-7, PostgreSQL 7.0 was released mid-year in 2000. […] it had an embedded language, PL/pgSQL. It actually supported several Languages… {{citation}}: horizontal tab character in |series= at position 10 (help)
  2. ^ "feature T322", SQL standard features (9 ed.) {{citation}}: Unknown parameter |published= ignored (help).
  3. ^ "PL/pgSQL – SQL Procedural Language". PostgreSQL. Retrieved 2007-11-15.
  4. ^ "PL/Java", Gborg (project), PostgreSQL.
  5. ^ "PL/Perl", Docs (current ed.), PostgreSQL.
  6. ^ "Parser stage", Docs (9 ed.), PostgreSQL.
  7. ^ Proposal: PL/pgPSM for pg9.3, by P. Stehule; and PosgreSQL-PSM-addon Manual