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:


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, Check it out.');


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