bugfix:获取带group_concat自定义聚集函数创建的视图定义报错
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -21,4 +21,5 @@ objfiles.txt
|
||||
/config.status
|
||||
/ereport.txt
|
||||
|
||||
/build/script/version.cfg
|
||||
/build/script/version.cfg
|
||||
/cmake_build
|
||||
@ -10831,7 +10831,7 @@ static void get_agg_expr(Aggref* aggref, deparse_context* context)
|
||||
#endif /* PGXC */
|
||||
char* funcname = generate_function_name(aggref->aggfnoid, nargs, NIL, argtypes, aggref->aggvariadic, &use_variadic);
|
||||
appendStringInfo(buf, "%s(%s", funcname, (aggref->aggdistinct != NIL) ? "DISTINCT " : "");
|
||||
|
||||
bool isGroupCatAggFunc = aggref->aggfnoid == GROUPCONCATFUNCOID;
|
||||
if (AGGKIND_IS_ORDERED_SET(aggref->aggkind)) {
|
||||
/*
|
||||
* Ordered-set aggregates do not use "*" syntax and we needn't
|
||||
@ -10854,7 +10854,7 @@ static void get_agg_expr(Aggref* aggref, deparse_context* context)
|
||||
int narg = 0;
|
||||
int start = 0;
|
||||
/* the first argument of group_concat() is separator, skip it */
|
||||
if (pg_strcasecmp(funcname, "group_concat") == 0) {
|
||||
if (isGroupCatAggFunc) {
|
||||
init = init->next;
|
||||
narg++;
|
||||
start++;
|
||||
@ -10884,7 +10884,7 @@ static void get_agg_expr(Aggref* aggref, deparse_context* context)
|
||||
}
|
||||
}
|
||||
|
||||
if (pg_strcasecmp(funcname, "group_concat") == 0) {
|
||||
if (isGroupCatAggFunc) {
|
||||
appendStringInfoString(buf, " SEPARATOR ");
|
||||
Const* con = (Const*)(((TargetEntry*)lfirst(list_head(aggref->args)))->expr);
|
||||
get_rule_separator(con, buf);
|
||||
|
||||
@ -59,3 +59,33 @@ create aggregate aggfns(integer,integer,text) (
|
||||
sfunc = aggfns_trans, stype = aggtype[],
|
||||
initcond = '{}'
|
||||
);
|
||||
create schema view_test_create_group_concat;
|
||||
set current_schema = 'view_test_create_group_concat';
|
||||
CREATE TABLE t1(a INT, b INT);
|
||||
CREATE FUNCTION _group_concat(text, text) RETURNS text
|
||||
LANGUAGE sql IMMUTABLE
|
||||
AS $_$
|
||||
SELECT CASE
|
||||
WHEN $2 IS NULL THEN $1
|
||||
WHEN $1 IS NULL THEN $2
|
||||
ELSE $1 || ', ' || $2
|
||||
END
|
||||
$_$;
|
||||
CREATE AGGREGATE group_concat(text) (
|
||||
SFUNC = _group_concat,
|
||||
STYPE = text
|
||||
);
|
||||
CREATE VIEW v4_4_2 AS SELECT group_concat(a::text) a FROM t1;
|
||||
select pg_get_viewdef('v4_4_2');
|
||||
pg_get_viewdef
|
||||
---------------------------------------------------------------
|
||||
SELECT group_concat((t1.a)::text SEPARATOR ',') AS a FROM t1;
|
||||
(1 row)
|
||||
|
||||
reset current_schema;
|
||||
drop schema view_test_create_group_concat cascade;
|
||||
NOTICE: drop cascades to 4 other objects
|
||||
DETAIL: drop cascades to table view_test_create_group_concat.t1
|
||||
drop cascades to function view_test_create_group_concat._group_concat(text,text)
|
||||
drop cascades to function view_test_create_group_concat.group_concat(text)
|
||||
drop cascades to view view_test_create_group_concat.v4_4_2
|
||||
|
||||
@ -71,3 +71,25 @@ create aggregate aggfns(integer,integer,text) (
|
||||
sfunc = aggfns_trans, stype = aggtype[],
|
||||
initcond = '{}'
|
||||
);
|
||||
|
||||
create schema view_test_create_group_concat;
|
||||
set current_schema = 'view_test_create_group_concat';
|
||||
CREATE TABLE t1(a INT, b INT);
|
||||
CREATE FUNCTION _group_concat(text, text) RETURNS text
|
||||
LANGUAGE sql IMMUTABLE
|
||||
AS $_$
|
||||
SELECT CASE
|
||||
WHEN $2 IS NULL THEN $1
|
||||
WHEN $1 IS NULL THEN $2
|
||||
ELSE $1 || ', ' || $2
|
||||
END
|
||||
$_$;
|
||||
CREATE AGGREGATE group_concat(text) (
|
||||
SFUNC = _group_concat,
|
||||
STYPE = text
|
||||
);
|
||||
|
||||
CREATE VIEW v4_4_2 AS SELECT group_concat(a::text) a FROM t1;
|
||||
select pg_get_viewdef('v4_4_2');
|
||||
reset current_schema;
|
||||
drop schema view_test_create_group_concat cascade;
|
||||
Reference in New Issue
Block a user