Custom SQL functions

You can write your own custom SQL functions and use them in formulas and in your SQL queries.

Note: this only applied to SQL queries running on Peliqan’s query engine Trino !

Custom functions are a great way to implement specific transformations, implement business logic, validate data etc. For example you could write a custom function to validate phone numbers or bar codes, to calculate product pricing or to feed a machine learning model.

Go to Admin > Database functions.

Add a new function, use only lower case for the function name, no spaces.

Next, write your anonymous function in Javascript. Maximum 5 parameters are allowed.

Here’s a simple example:

(param1, param2) => {
  return param1 + param2;

Once done, you can use your custom function in any SQL query.

Example for the above function, that was saved using the name “my_func”:

SELECT my_func(price, vat) AS total_price, product_name FROM products