admin管理员组文章数量:1313598
I need to convert filenames stored in a snowflake table to camel case values. I was able to convert it but file extension is also getting Initcapped(.Txt). Please suggest solution (preferably regex).
Source: 'ABC_defg_HiJk_lMn_123.txt'.
Work In Progress: 'Abc_Defg_Hijk_lmn_123.Txt'.
Required: 'Abc_Defg_Hijk_lmn_123.txt'.
SELECT REPLACE(INITCAP(REPLACE(LOWER('ABC_defg_HiJk_lMn_123.txt'),'_',' ')),' ','_');
I need to convert filenames stored in a snowflake table to camel case values. I was able to convert it but file extension is also getting Initcapped(.Txt). Please suggest solution (preferably regex).
Source: 'ABC_defg_HiJk_lMn_123.txt'.
Work In Progress: 'Abc_Defg_Hijk_lmn_123.Txt'.
Required: 'Abc_Defg_Hijk_lmn_123.txt'.
SELECT REPLACE(INITCAP(REPLACE(LOWER('ABC_defg_HiJk_lMn_123.txt'),'_',' ')),' ','_');
Share
Improve this question
edited Jan 30 at 23:04
BabaGee
asked Jan 30 at 23:01
BabaGeeBabaGee
111 silver badge5 bronze badges
2 Answers
Reset to default 0You could use a substring operation to separate the filename from the extension. Then, use INITCAP()
on the filename alone, and join together at the end with the original extension:
WITH yourTable AS (
SELECT 'ABC_defg_HiJk_lMn_123.txt' AS filename
)
SELECT
REPLACE(INITCAP(REPLACE(LOWER(REGEXP_SUBSTR(filename, '[^.]+')), '_', ' ')), ' ', '_')
||
REGEXP_SUBSTR(filename, '\\..+') AS fileout
FROM yourTable;
you can split based on .
and perform the operations and then concat the extension.
WITH test AS (
SELECT 'ABC_defg_HiJk_lMn_123.txt' AS filename
)
,splitt as
( SELECT
SPLIT_PART(filename, '.', 1) AS name_part,
SPLIT_PART(filename, '.', 2) AS extension_part
FROM
test)
select REPLACE(INITCAP(REPLACE(LOWER(name_part),'_',' ')),' ','_') ||'.' || extension_part as camel_case
from splitt ;
本文标签: sqlSnowflake Regex to Camel case file nameStack Overflow
版权声明:本文标题:sql - Snowflake Regex to Camel case file name - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741932415a2405650.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论