Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon redshift 将一行的值分散到红移表中的多个列上?_Amazon Redshift - Fatal编程技术网

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()吗