-
-
Save zhangw/d7ffaf93c6a639c84989d19eecdc6f3a to your computer and use it in GitHub Desktop.
Example of building a simple UDF compared to the standard SQL function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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