Sublime Forum

Syntax highligthing for PostgreSQL procedural languages

#1

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]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;[/code]

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

0 Likes

#2

Here is a second example (CoffeeScript):

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.

0 Likes

#3

Was there ever any update or plugin to solve this?

Thanks.

0 Likes