在 SQL 中,有没有办法拆分存储为列表的 SQL 中的列?
In SQL, is there a way to split up a column in SQL that is stored as a list?
我目前有一个 table,无论出于何种原因,其中有一列存储为列表。看起来如下:
Symbol Exchange Price
AAPL [NYSE, CHX, PHLX] 22.02
AAPL [BSE, MS4X] 23.11
有没有办法使用 SQL 拆分 table,以便将列扩展为如下所示:
Symbol Exchange Price
AAPL NYSE 22.02
AAPL CHX 22.02
AAPL PHLX 22.02
AAPL BSE 23.11
AAPL MS4X 23.11
基本上目标是分解交换列,以便它有自己的单独条目作为列表。
谢谢
假设是数组,可以用unnest()
:
select t.symbol, u.exchange, t.price
from t cross join
unnest(t.exchanges) u(exchange);
我目前有一个 table,无论出于何种原因,其中有一列存储为列表。看起来如下:
Symbol Exchange Price
AAPL [NYSE, CHX, PHLX] 22.02
AAPL [BSE, MS4X] 23.11
有没有办法使用 SQL 拆分 table,以便将列扩展为如下所示:
Symbol Exchange Price
AAPL NYSE 22.02
AAPL CHX 22.02
AAPL PHLX 22.02
AAPL BSE 23.11
AAPL MS4X 23.11
基本上目标是分解交换列,以便它有自己的单独条目作为列表。
谢谢
假设是数组,可以用unnest()
:
select t.symbol, u.exchange, t.price
from t cross join
unnest(t.exchanges) u(exchange);