I am recently inclined in PostgreSQL and trying to make a ListAggregation function as given here the only difference being tha开发者_如何学编程t I am trying to use CONCAT instead of TextCat . My function is as under
CREATE AGGREGATE ListAggregation(
basetype = Text,
sfunc = Concat,
stype = Text,
initcond = ''
);
It is throwing error
ERROR: function concat(text, text) does not exist
********** Error **********
ERROR: function concat(text, text) does not exist
SQL state: 42883
what mistake I am making...please help
N.B.~ I have even looked at the example given here
Thanks
Interesting, what are you palanning to do? There is already a string_agg()
aggregate function in PostgreSQL 9.0+ ...
You should create state change function sfunc to implement an aggregate with the signature: sfunc( state, value ) ---> next-state
-- sfunc:
CREATE OR REPLACE FUNCTION concat(text, text)
RETURNS text
LANGUAGE SQL
AS $$
SELECT $1||$2;
$$;
-- Aggregate:
CREATE AGGREGATE ListAggregation(
basetype = text,
sfunc = concat,
stype = text,
initcond = ''
);
-- Testing:
WITH test(v) AS (VALUES
('AAAA'),
('BBBB'),
('1111'),
('2222') )
SELECT ListAggregation(v) FROM test;
精彩评论