Skip to content

Instantly share code, notes, and snippets.

@nicosuave
Last active December 1, 2024 05:59
Show Gist options
  • Save nicosuave/3dad89db7ca638ea111201b7cb365a44 to your computer and use it in GitHub Desktop.
Save nicosuave/3dad89db7ca638ea111201b7cb365a44 to your computer and use it in GitHub Desktop.
DuckDB url_encode
CREATE OR REPLACE MACRO url_encode(input_string) AS (
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
input_string,
' ', '%20'
),
'!', '%21'
),
'"', '%22'
),
'#', '%23'
),
'$', '%24'
),
'%', '%25'
),
'&', '%26'
),
'''', '%27' -- Corrected single-quote encoding
),
'(', '%28'
),
')', '%29'
),
'*', '%2A'
),
'+', '%2B'
),
',', '%2C'
),
'/', '%2F'
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment