'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?
Solution 1:[1]
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 |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Simeon Pilgrim |
