Skip to content

Instantly share code, notes, and snippets.

@lacerogers20
Last active August 26, 2022 09:38
Show Gist options
  • Save lacerogers20/41911b69d159d507b1a88e5b6ed05f23 to your computer and use it in GitHub Desktop.
Save lacerogers20/41911b69d159d507b1a88e5b6ed05f23 to your computer and use it in GitHub Desktop.
Example of building a simple UDF compared to the standard SQL function
CREATE TEMP FUNCTION
PROPER(str STRING) AS ((
SELECT
STRING_AGG(CONCAT(UPPER(SUBSTR(w,1,1)), LOWER(SUBSTR(w,2))), ' '
ORDER BY
pos)
FROM
UNNEST(SPLIT(str, ' ')) w
WITH
OFFSET
pos ));
SELECT
string,
PROPER(string) AS proper_string_udf,
INITCAP(string) AS proper_string_function,
FROM (
SELECT
'i love data warehouses' AS string )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment