【问题标题】:Element Numeric Position for Array数组的元素数值位置
【发布时间】:2021-09-16 20:25:25
【问题描述】:

我知道在 Spark/Impala 中,你可以使用 array_column.POS 表示数组中每个元素的数值位置。

您如何为 Presto 编写此内容?看起来Array_Position 不起作用?

【问题讨论】:

    标签: sql arrays presto trino


    【解决方案1】:

    您可以使用subscript operator 按位置访问元素:

    WITH t(array_column) AS (VALUES array['the', 'quick', 'brown', 'fox'])
    SELECT array_column[2] 
    FROM t
    

    =>

     _col0
    -------
     quick
    (1 row)
    

    您可以使用array_position 查找值在数组中的位置:

    WITH t(array_column) AS (VALUES array['the', 'quick', 'brown', 'fox'])
    SELECT array_position(array_column, 'quick') 
    FROM t
    

    =>

     _col0
    -------
         2
    (1 row)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多