Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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
postgresql中的Concat函数_Sql_Postgresql_Hive_Coalesce - Fatal编程技术网

postgresql中的Concat函数

postgresql中的Concat函数,sql,postgresql,hive,coalesce,Sql,Postgresql,Hive,Coalesce,我在配置单元中有下面的select语句。它执行得非常好 蜂房 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(文本,

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

蜂房

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(文本,未知)不存在
提示:没有与给定名称和参数类型匹配的函数。您可能需要添加显式类型转换

在postgresql中:

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

有人能解释一下吗?

|
代替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;

也可以考虑使用函数:

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

这应该适用于文本列。列的类型是什么?
concat\u ws()
可以简化此字符串表达式。@klin:数据类型是text
concat()
是在Postgres 9.1中引入的,可能您使用的是较旧的版本。Upgrade.column数据类型是文本。甚至我也尝试过上面明确定义数据类型的查询。但它给出了相同的错误。@user8545255
选择COALESCE(产品名称,(TRIM(产品id)| |-“| TRIM(平面代码)| |-未知”))正如tablename;
中的product_name一样,这是否有效?请注意,如果要连接的任何字符串为null,则| |将返回null。concat函数不会这样做。