假設我有一個像xxx.yyy. 我想“提取”xxx.yyy并yyy給他們起名字。
我可以regexp_matches像這樣在 postgres 中使用:
with const as (
SELECT regexp_matches('xxx.yyy' ,'((. \.).*)') as foo
)
select foo from const;
這將回傳:
{xxx.yyy,xxx.}
現在我知道我可以通過做(...)[1]等從結果中獲取單個元素,但我想知道是否有辦法做這樣的事情:
with const as (
SELECT regexp_matches('xxx.yyy' ,'((. \.).*)') as (bar, baz)
)
select bar, baz from const;
上面的語法當然給了我一個錯誤。所以我想我想知道是否有辦法在 SQL 中的陣列上解構/模式匹配。
uj5u.com熱心網友回復:
就像這樣
with const as (
SELECT regexp_matches('xxx.yyy' ,'((. \.).*)') as foo
)
select unnest(foo) from const;
或命名元組
with const as (
SELECT regexp_matches('xxx.yyy' ,'((. \.).*)') as foo
)
select * from unnest((select foo from const), ARRAY['bar','baz']) as x(a,b);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/517930.html
上一篇:如何劃分兩列并每行顯示結果?
