Skip to content

Instantly share code, notes, and snippets.

@christinebuckler
Created November 12, 2018 04:10
Show Gist options
  • Select an option

  • Save christinebuckler/d15406e9920d81b7ea801b37695fd688 to your computer and use it in GitHub Desktop.

Select an option

Save christinebuckler/d15406e9920d81b7ea801b37695fd688 to your computer and use it in GitHub Desktop.
Redshift - python UDF for decoding url strings
-- This example decodes percent-encoded sequences from url parameters,
-- replaces plus signs with spaces, and converts to all lowercase.
CREATE OR REPLACE FUNCTION schema_name.function_name(original TEXT)
RETURNS VARCHAR IMMUTABLE AS
$$
import urllib
u = urllib.unquote_plus(original)
return u.lower()
$$
LANGUAGE plpythonu;
SELECT schema_name.function_name(original_url)
FROM schema_name.table_name;
@MemphisMeng
Copy link

Awesome, thanks for your sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment