How to convert a string into a url-friendly string in Snowflake SQL?

I am working in Snowflake and have a column pets that I'm trying to put into a url friendly format so they can be concatenated to links within Metabase. Example:

'Tom & Jerry' -> 'Tom%20%26%20Jerry'

Is there a function in Snowflake that does this?

1 answer

  • answered 2022-05-07 01:36 Simeon Pilgrim

    I don't think there is one. But Javascript has sush a thing, so we can wrap that into a function:

    create function urlencodestring(str string)
    returns string
    language javascript
    strict
    as
    '
        return encodeURIComponent(STR);
    ';
    

    then go crazy:

    select urlencodestring('Tom & Jerry');
    
    URLENCODESTRING('TOM & JERRY')
    Tom%20%26%20Jerry

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum