mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
Fix finalization for json_objectagg and friends
Commitf4fb45d15c
misguidedly tried to free some state during aggregate finalization for json_objectagg. This resulted in attempts to access freed memory, especially when the function is used as a window function. Commit4eb9798879
attempted to ameliorate that, but in fact it should just be ripped out, which is done here. Also add some regression tests for json_objectagg in various flavors as a window function. Original report from Jaime Casanova, diagnosis by Andres Freund. Discussion: https://postgr.es/m/YkfeMNYRCGhySKyg@ahch-to
This commit is contained in:
@ -292,6 +292,24 @@ SELECT JSON_OBJECT('foo' : '1' FORMAT JSON, 'bar' : 'baz' RETURNING json);
|
||||
|
||||
DROP VIEW json_object_view;
|
||||
|
||||
SELECT to_json(a) AS a, JSON_OBJECTAGG(k : v WITH UNIQUE KEYS) OVER (ORDER BY k)
|
||||
FROM (VALUES (1,1), (2,2)) a(k,v);
|
||||
|
||||
SELECT to_json(a) AS a, JSON_OBJECTAGG(k : v WITH UNIQUE KEYS) OVER (ORDER BY k)
|
||||
FROM (VALUES (1,1), (1,2), (2,2)) a(k,v);
|
||||
|
||||
SELECT to_json(a) AS a, JSON_OBJECTAGG(k : v ABSENT ON NULL WITH UNIQUE KEYS)
|
||||
OVER (ORDER BY k)
|
||||
FROM (VALUES (1,1), (1,null), (2,2)) a(k,v);
|
||||
|
||||
SELECT to_json(a) AS a, JSON_OBJECTAGG(k : v ABSENT ON NULL)
|
||||
OVER (ORDER BY k)
|
||||
FROM (VALUES (1,1), (1,null), (2,2)) a(k,v);
|
||||
|
||||
SELECT to_json(a) AS a, JSON_OBJECTAGG(k : v ABSENT ON NULL)
|
||||
OVER (ORDER BY k RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
|
||||
FROM (VALUES (1,1), (1,null), (2,2)) a(k,v);
|
||||
|
||||
-- Test JSON_ARRAY deparsing
|
||||
EXPLAIN (VERBOSE, COSTS OFF)
|
||||
SELECT JSON_ARRAY('1' FORMAT JSON, 2 RETURNING json);
|
||||
|
Reference in New Issue
Block a user