Home Download Buy Blog Forum Support

Syntax highligthing for PostgreSQL procedural languages

Syntax highligthing for PostgreSQL procedural languages

Postby oberstet on Wed Mar 20, 2013 11:50 am

Hello,

PostgreSQL has a flexible procedural language system that allows to create database stored procedures in different languages, e.g. here is one using JavaScript:

Code: Select all
CREATE TYPE rec AS (i integer, t text);
CREATE FUNCTION set_of_records() RETURNS SETOF rec AS
$$
    // plv8.return_next() stores records in an internal tuplestore,
    // and return all of them at the end of function.
    plv8.return_next( { "i": 1, "t": "a" } );
    plv8.return_next( { "i": 2, "t": "b" } );

    // You can also return records with an array of JSON.
    return [ { "i": 3, "t": "c" }, { "i": 4, "t": "d" } ];
$$
LANGUAGE plv8;


Everything between the $$ is source code in language specified after the LANGUAGE token.

Is there a way to highlight everything outside $$ in PL/SQL syntax and everything between the $$ in the specified language?

Note that there are multiple supported languages: PL/pgSQL, PL/v8, PL/Python, PL/R and so on.

Thanks!
Tobias
oberstet
 
Posts: 2
Joined: Wed Mar 20, 2013 11:45 am

Re: Syntax highligthing for PostgreSQL procedural languages

Postby oberstet on Wed Mar 20, 2013 1:02 pm

Here is a second example (CoffeeScript):

Code: Select all
CREATE OR REPLACE FUNCTION fibonacci(n integer)
RETURNS integer LANGUAGE plcoffee IMMUTABLE STRICT
AS
$function$
   fibonacci = (x)->
     return 0 if x == 0
     return 1 if x == 1
     return fibonacci(x-1) + fibonacci(x-2)
   return fibonacci n
$function$;


The $ markers work by having matching $x$ where is can be empty or some identifier.

The LANGUAGE can also appear at the beginning.
oberstet
 
Posts: 2
Joined: Wed Mar 20, 2013 11:45 am


Return to General Discussion

Who is online

Users browsing this forum: Exabot [Bot], rgidney and 31 guests