Last active
August 26, 2022 09:38
-
-
Save lacerogers20/41911b69d159d507b1a88e5b6ed05f23 to your computer and use it in GitHub Desktop.
Example of building a simple UDF compared to the standard SQL function
This file contains 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