【发布时间】:2017-04-10 16:26:43
【问题描述】:
我有一个 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=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_PART(SPLIT_PART(SPLIT_PART(url, '?', 2), '&', {i}), '=', 1) 和SPLIT_PART(SPLIT_PART(SPLIT_PART(url, '?', 2), '&', {i}), '=', 2) 解析出所需的字段。
【问题讨论】:
-
Redshift有
regexp_split_to_table()吗?
标签: amazon-redshift