试图在列中更改字符串(Snowflake SQL)

发布于 2025-02-09 21:03:33 字数 319 浏览 0 评论 0 原文

我在雪花中的桌子上有一个名为“ A”的列。在此列中,我具有诸如“杂货店”,“邮局”,“ nordstromrackstore” 等的值。这些值当前在骆驼案中,但我想更改它们,以便它们遵循格式“ grocery_store”,“ post_office”,“ nordstrom_rack_store” 等。有没有办法将值更改为所有大写,并在此中被一个下划线隔开的单词?我不确定如何将Regex用于骆驼盒格式。或者,或者甚至可以将结果格式更改为骆驼案例?如Change 中的“ Grocery_store” “杂货店” ?谢谢!

I have a column in my table in Snowflake called "A". In this column I have values such as "groceryStore", "postOffice", "nordstromRackStore" etc. The values are currently in camel case but I would like to change them so that they follow the format "GROCERY_STORE", "POST_OFFICE", "NORDSTROM_RACK_STORE" and so on. Is there a way to change the values to be all uppercase and have the words separated by an underscore in this? I'm not sure how to use regex for camel case format. Or even alternatively, is there a way to change the result format into camel case? As in change "GROCERY_STORE" to "groceryStore"? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本王不退位尔等都是臣 2025-02-16 21:03:33

它( Regexp_replace ),除非我缺少问题中的某些内容。

数据

with cte(col1) as (
 select * from values
 ('nordstromRackStore'),('groceryStore'),('postOffice'),('thisIsComplexCamelCaseAndLongToo')
)SELECT * from cte;
-Col1
Nordstromrackstore
杂货店
邮局

替换

with cte(col1) as (
  select * from values
 ('nordstromRackStore'),('groceryStore'),('postOffice'),('thisIsComplexCamelCaseAndLongToo')
)SELECT upper(regexp_replace(col1,'([A-Z])', '_\\1', 2)) as snake_case_col from cte;
-snake_case_col
iscomplexcamelcaseandlongtoo
原始
nordstrom_rack
nordstrom

It (REGEXP_REPLACE), seems to work, unless I am missing something in the question.

Original data -

with cte(col1) as (
 select * from values
 ('nordstromRackStore'),('groceryStore'),('postOffice'),('thisIsComplexCamelCaseAndLongToo')
)SELECT * from cte;
COL1
nordstromRackStore
groceryStore
postOffice
thisIsComplexCamelCaseAndLongToo

After replace -

with cte(col1) as (
  select * from values
 ('nordstromRackStore'),('groceryStore'),('postOffice'),('thisIsComplexCamelCaseAndLongToo')
)SELECT upper(regexp_replace(col1,'([A-Z])', '_\\1', 2)) as snake_case_col from cte;
SNAKE_CASE_COL
NORDSTROM_RACK_STORE
GROCERY_STORE
POST_OFFICE
THIS_IS_COMPLEX_CAMEL_CASE_AND_LONG_TOO
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文