连接字符串和数组 - Amazon Athena
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

连接字符串和数组

连接字符串

要连接两个字符串,可以使用双管道 || 运算符,如以下示例中所示。

SELECT 'This' || ' is' || ' a' || ' test.' AS Concatenated_String

此查询返回:

Concatenated_String This is a test.

您可以使用 concat() 函数来获得相同的结果。

SELECT concat('This', ' is', ' a', ' test.') AS Concatenated_String

此查询返回:

Concatenated_String This is a test.

连接数组

您可以使用相同的技术来连接数组。

要连接多个数组,请使用双管道 || 运算符。

SELECT ARRAY [4,5] || ARRAY[ ARRAY[1,2], ARRAY[3,4] ] AS items

此查询返回:

items [[4, 5], [1, 2], [3, 4]]

要将多个数组组合成一个数组,请使用双管道运算符或 concat() 函数。

WITH dataset AS ( SELECT ARRAY ['Hello', 'Amazon', 'Athena'] AS words, ARRAY ['Hi', 'Alexa'] AS alexa ) SELECT concat(words, alexa) AS welcome_msg FROM dataset

此查询返回:

welcome_msg [Hello, Amazon, Athena, Hi, Alexa]

有关 concat() 或其他字符串函数的更多信息,请参阅 Presto 文档中的字符串函数和运算符