Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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
Sql CONCAT_WS的Presto等价物_Sql_Presto_String Concatenation - Fatal编程技术网

Sql CONCAT_WS的Presto等价物

Sql CONCAT_WS的Presto等价物,sql,presto,string-concatenation,Sql,Presto,String Concatenation,我正在寻找一个函数,它可以在Presto中连接两个带有分隔符(如下划线)的列。要处理: select concat_ws(',', col1, col2) 您可以使用: select substr( concat(case when col1 is not null then ',' || col1 else '' end, case when col2 is not null then ',' || col2 else '' end

我正在寻找一个函数,它可以在Presto中连接两个带有分隔符(如下划线)的列。

要处理:

select concat_ws(',', col1, col2)
您可以使用:

select substr( concat(case when col1 is not null then ',' || col1 else '' end,
                      case when col2 is not null then ',' || col2 else '' end

                     ),
                2
             )

这会将非空值连接到字符串中。结果字符串将以逗号开头。
substr()
删除第一个字符。

您正在此处查找
array\u join
函数,请参阅

select concat(col1, ',', col2) 
数组\u连接(x,分隔符,空\u替换)→ 瓦尔查尔

使用 分隔符和替换空值的可选字符串

示例:
列为c1、c2。当然,您可以添加更多:

结果将是:
1_2
3_4
5_NA

7_8

这已经被添加到PrestoSQL(现在的Trino)中,并在几个版本中恢复:


presto不支持上的逻辑运算符strings@MTT . . . 我修复了concat运算符,
+
不是逻辑运算符,而是算术运算符。这个答案是不正确的。它不能正确处理
NULL
值。
WITH  demo_table (c1,c2) AS 
    (SELECT * FROM  (VALUES  (1,2),(3,4),(5,null),(7,8) ))
SELECT array_join(array[c1,c2], '_', 'NA')
FROM demo_table
concat_ws(string0, string1, ..., stringN) → varchar#
Returns the concatenation of string1, string2, ..., stringN using string0 as a separator. If string0 is null, then the return value is null. Any null values provided in the arguments after the separator are skipped.

concat_ws(string0, array(varchar)) → varchar
Returns the concatenation of elements in the array using string0 as a separator. If string0 is null, then the return value is null. Any null values in the array are skipped.