The PL/V8 Language

RdbHost now supports using the language JavaScript in creating functions. The language is used to define functions (aka procedures) that can be called from SQL, just as a native procedure can. The embedded language system is known as PL/V8 since it used Google's V8 JavaScript engine.

General Merits

PL/V8 programming allows database functions to be implemented in JavaScript, with control flow more sophisticated than that allowed by plain SQL, or even PL/pgSQL. Later statements can depend on the outcome of earlier statements, coding with conditional blocks. The set of queries and conditional blocks can be requested of the server in one request, reducing the time required for the sequence to execute.

From the plv8js wiki website, supported features include:

  • Functions can receive any arguments, and return a value or set of records.
  • Execute any SQL commands with built-in plv8.execute() function.
  • Automatic data conversion between PostgreSQL and JavaScript, including string, numbers, timestamps, arrays, and records.
  • Records are converted to JSON which keys are column names.
  • Other types are converted to strings.
  • Partial support to write TRIGGER handlers.
  • Inline commands with DO statement for PG 9.0 or newer versions.