GreenPlum - 在greenplum中的'concat'功能

问题描述 投票:0回答:4

GreenPlum中有'concat'功能吗?我可以在postgresql中使用concat函数,它运行良好,但是当我在Greenplum中使用它时,我收到了一个错误。

select concat('a', 'b');
ERROR:  function concat(unknown, unknown) does not exist at character 8
HINT:  No function matches the given name and argument types. You may need to add explicit type casts.
LINE 1: select concat('a', 'b');
               ^

是否有其他功能可以代替GreenPlum中的“concat”功能?我试图创建一个函数而不是它,但也有一些语法错误。

CREATE OR REPLACE FUNCTION my_concat(VARIADIC arr VARCHAR[] ) RETURNS VARCHAR AS  $$  SELECT array_to_string(arr, '');  $$  LANGUAGE SQL;
ERROR:  syntax error at or near "VARCHAR" at character 51
LINE 1: CREATE OR REPLACE FUNCTION my_concat(VARIADIC arr VARCHAR[] ...
                                                          ^

有人可以帮忙吗?非常感谢!

concat greenplum
4个回答
2
投票

像大多数数据库一样,Greenplum使用“||”将两个字符串连接在一起。

SELECT 'Green' || 'plum';

结果:

Greenplum

0
投票

这是一个多方面的问题,你有使用||使用联系功能的地方。


0
投票

Greenplum还没有concat功能。可能是你可以修改你的代码使用“||”而不是concat。


0
投票

好,

首先,我同意您应该替换您的代码以使用正确的SQL语法'||'用于连接。

如果你真的想创建一个模拟concat的函数,你可以做类似的事情:

create or replace function myschema.concat(arg1 text, arg2 text)
returns text as
$body$
declare
    v_arg1  text;
    v_arg2  text;
begin
    v_arg1  := arg1;
    v_arg2  := arg2;

    return v_arg1 || v_arg2;
end
$body$
language plpgsql volatile;

然后,查询将工作:

select myschema.concat('test1', 'test2');
>>test1test2
© www.soinside.com 2019 - 2024. All rights reserved.