Amazon redshift 将一行的值分散到红移表中的多个列上?
我有一个红移表,其示例行具有以下结构:Amazon redshift 将一行的值分散到红移表中的多个列上?,amazon-redshift,Amazon Redshift,我有一个红移表,其示例行具有以下结构: id url 12345 http://www.things.com/details/?foo=hello&bar=world&baz=John+Smith 45678 http://www.things.com/details/?foo=hello&bar=america&booz=Howard+Jones&other_field=Por
id url
12345 http://www.things.com/details/?foo=hello&bar=world&baz=John+Smith
45678 http://www.things.com/details/?foo=hello&bar=america&booz=Howard+Jones&other_field=Portugal
我想提取url中?
之后的所有内容,对于每个&
,将=
左侧的值添加到键列,将右侧的值添加到值列。给定URL中的和数量不确定。所需的输出如下:
id key value
12345 foo hello
12345 bar world
12345 baz John+Smith
45678 foo hello
45678 bar america
45678 booz Howard+Jones
45678 other_field Portugal
我现在的解决方案是选择一个相当高的数字,并编写一个Python脚本,用新的UNION ALL
为每个整数编写相同的查询。在每次迭代中,我使用SPLIT\u-PART(SPLIT\u-PART(url,,?,,,,,,,{I}),'=',1)
和SPLIT\u-PART(SPLIT\u-PART(url,,,,,,,,,,,,,,{I},,,,,,,{/code>解析出所需的字段。这是一些其他问题的重复:
我不认为在Redshift中很容易实现,因为它没有将一行转换为多行的函数
我提到的相关问题也提供了一些可能有用的技巧。我认为最好的方法是使用一个序列号表(没有任何连接谓词)连接,并将该数字用于SPLIT\u PART
,可能还有一个过滤器来消除不匹配的行
其他一些系统也有这方面的功能,例如Postgres有regexp\u split\u to\u array
和regexp\u split\u to\u table
,Snowflake有split
+flatte
(免责声明-我在这个系统上工作)。这是一些其他问题的重复:
我不认为在Redshift中很容易实现,因为它没有将一行转换为多行的函数
我提到的相关问题也提供了一些可能有用的技巧。我认为最好的方法是使用一个序列号表(没有任何连接谓词)连接,并将该数字用于SPLIT\u PART
,可能还有一个过滤器来消除不匹配的行
其他一些系统有这样的功能,例如Postgres有regexp\u split\u to\u array
和regexp\u split\u to\u table
,Snowflake有split
+flatte
(免责声明-我在这个系统上工作)。Redshift有regexp\u split\u to\u to\u table()
?Redshift有regexp\u split\u to\u to\u table()吗
?