【问题标题】:string_to_array functionstring_to_array 函数
【发布时间】:2016-08-12 06:29:04
【问题描述】:

我在 redshift case 语句中使用了 sting_to_array 函数。但我得到一个错误,比如 -

[0A000] ERROR: Specified types or functions (one per INFO message) not supported on Redshift tables.

可能是什么问题?

下面是示例代码 -

SELECT
  CASE 
    WHEN upper(url) LIKE upper('%utm_source%')
             THEN  (string_to_array(url, '&'))[1]
END as utm_source,
FROM
TEMP.table_data a2;

基本上我的网址是这种格式 -

utm_source=257509081c6f53&utm_medium=internet&utm_campaign=messenger-android&utm_term=search_keyword&utm_content=new_products

我的目标是只提取 utm_* 值

【问题讨论】:

  • Redshift 手册对 `string_to_array 有什么说法?

标签: postgresql amazon-redshift


【解决方案1】:

Redshift 不支持数组函数和运算符:http://docs.aws.amazon.com/redshift/latest/dg/c_unsupported-postgresql-functions.html

请尝试使用SPLIT_PART 函数:

SELECT
  CASE 
    WHEN upper(url) LIKE upper('%utm_source%')
      THEN SPLIT_PART(url, '&', 1)
  END as utm_source
FROM
TEMP.table_data a2;

注意:SPLIT_PART函数从1开始计数。

【讨论】:

    猜你喜欢
    • 2012-10-05
    • 2012-08-03
    • 1970-01-01
    • 2015-04-14
    • 2021-11-21
    • 1970-01-01
    • 2016-01-28
    • 2020-02-16
    • 2017-08-22
    相关资源
    最近更新 更多