我使用postgresql创建了一个函数。但是当我尝试执行它时,此函数返回错误。
错误"ERROR: syntax error at or near "||"
CREATE OR REPLACE FUNCTION search_address_book(address_ids character)
RETURNS void AS
$BODY$
SET sqlStatement = 'select * from addressbook';
SET address_ids = 'Post' || 'greSQL';
$BODY$
LANGUAGE 'sql' STABLE
COST 100;
我的服务器版本是8.3.14。这是错的吗?我如何在postgresql中连接两个字符串?
答案 0 :(得分:4)
要使用变量,您需要plpgsql
函数:
CREATE OR REPLACE FUNCTION search_address_book(address_ids character)
RETURNS void AS
$BODY$
declare
sqlStatement text;
address_ids text;
begin
sqlStatement := 'select * from addressbook';
address_ids := 'Post' || 'greSQL';
end
$BODY$
LANGUAGE plpgsql STABLE;