我在postgres中得到了下面的结果,有点卡住了。这些值来自一个上传的excel文件,所以我这里有一列逗号分隔的值,第一行是标题,后面所有的都是值
| values ||col1,col2,col3||val1,val2,val3||val1,val2,val3|
| values |
|col1,col2,col3|
|val1,val2,val3|
我的问题是如何达到下面描述的我想要的输出
| col1 | col2 | col3 || val1 | val2 | val3 || cal1 | val2 | val3 |
| col1 | col2 | col3 |
| val1 | val2 | val3 |
| cal1 | val2 | val3 |
提前谢谢!
nzk0hqpo1#
一个简单的方法是 split_part() :
split_part()
select split_part(col, ',', 1) as col1, split_part(col, ',', 2) as col2, split_part(col, ',', 3) as col3from t;
select split_part(col, ',', 1) as col1,
split_part(col, ',', 2) as col2,
split_part(col, ',', 3) as col3
from t;
但是,这不允许您重新指定列名。这将是相当棘手的。我建议您只需对这些值进行硬编码,然后删除看起来像是包含列名的行。
gijlo24d2#
这只是一个关于如何的基本草案。
GetFirstRow().SplitByNewLine().SplitByComma().SortByIndexIntoTheeseLists(hereAreTheLists).....Profit();
GetFirstRow()
.SplitByNewLine()
.SplitByComma()
.SortByIndexIntoTheeseLists(hereAreTheLists)
....
.Profit();
希望对你有帮助。
2条答案
按热度按时间nzk0hqpo1#
一个简单的方法是
split_part()
:但是,这不允许您重新指定列名。这将是相当棘手的。我建议您只需对这些值进行硬编码,然后删除看起来像是包含列名的行。
gijlo24d2#
这只是一个关于如何的基本草案。
希望对你有帮助。