concat函数

qzwqbdag  于 2021-06-24  发布在  Hive
关注(0)|答案(2)|浏览(325)

我在配置单元中有下面的select语句。它执行得非常好。
在Hive里

select
COALESCE(product_name,CONCAT(CONCAT(CONCAT(TRIM(product_id),' - 
'),trim(plan_code)),' - UNKNOWN')) as product_name
from table name;

我正试图在postgresql中使用相同的select语句,但它给了我一个错误
查询执行失败
原因:
sql错误[42883]:错误:函数concat(text,未知)不存在
提示:没有函数与给定的名称和参数类型匹配。您可能需要添加显式类型转换。
在postgresql中:

select
COALESCE(product_name,CONCAT(CONCAT(CONCAT(TRIM(product_id),' - 
'),trim(plan_code)),' - UNKNOWN')) as product_name
from table name;

有人能解释一下吗?

wfauudbj

wfauudbj1#

您也可以考虑使用格式函数:

SELECT coalesce(product_name, format('%s - %s - UNKNOWN', trim(product_id), trim(plan_code)))
ccrfmcuu

ccrfmcuu2#

而不是concat尝试 || :

SELECT COALESCE(product_name, 
        (TRIM(product_id) || ' - ' || TRIM(plan_code) || ' - UNKNOWN')
       ) AS product_name 
FROM tablename;

或者只是一个简单的concat:

SELECT COALESCE(product_name, 
         CONCAT(TRIM(product_id)::text, ' - ', TRIM(plan_code)::text, ' - UNKNOWN') 
       ) AS product_name
FROM tablename;

相关问题