14 Dec 18 · Ryan-Dallas ·       Add to Favorites  

Convert first letter to uppercase in Big Query

I want to convert "i want to buy bananas" -> "I Want To Buy Bananas". How do I it?

Below example is fr BigQuery Standrad SQL

#standardSQL
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
));
WITH `project.dataset.table` AS (
  SELECT 'i Want to buy bananas' str
)
SELECT str, PROPER(str) proper_str
FROM `project.dataset.table`  

result is

Row str                     proper_str   
1   i Want to buy bananas   I Want To Buy Bananas    

Ryan-Dallas

posted on 14 Dec 18

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds

Copied