Converting camelCase and SNAKE_CASE

Snowflake in the Carolinas > SnowSQL > UDF > Converting camelCase and SNAKE_CASE

In programming and string matching, use of camelCase and SNAKE_CASE are common. Here are two simple Snowflake UDFs to convert between the two.

create or replace function camelToSnake("s" string)
returns string
language sql
    upper(regexp_replace(s,'([A-Z])', '_\\1', 2))

select camelToSnake('quickBrownFox');

create or replace function snakeToCamel("s" string)
returns string
language javascript
strict immutable
const snakeToCamel = str =>
  str.toLowerCase().replace(/([-_][a-z])/g, group => group
      .replace('-', '')
      .replace('_', '')
return snakeToCamel(s);

select snakeToCamel('QUICK_BROWN_FOX');

Leave a Reply

Your email address will not be published.

Theme: Overlay by Kaira