Scalar User Defined Function (UDF) in CockroachDB is here!


User Defined Functions (UDF) in CockroachDB are now available (in Beta). Try it for yourself.

Here is a UDF that I created for creating hyperlinks for URLs in any input string:

Input

CREATE OR REPLACE FUNCTION convert_url_to_hyperlink(str varchar) RETURNS varchar AS 'SELECT regexp_replace(str, ''(http|ftp|https):\/\/([\w_-]+(?:(?:.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])'', ''<a href="https://\2\3">\2\3</a>'')' LANGUAGE SQL;

User Defined Function (UDF) definition

select convert_url_to_hyperlink('this is the link, https://www.google.com/test. Check it out.');

Output

this is the link, <a href="https://www.google.com/test">www.google.com/test</a>. Check it out.
User Defined Function (UDF) definition using CREATE FUNCTION
Using the User Defined Function (UDF)