PG::UndefinedFunction: ERROR: function array_append(anyarray, anyelement) does not exist
You are using PostGreSQL 14, aren't you ?
Because with postgres 13 and before, this should work, see the test result in dbfiddle.
And I confirm that this doesn't work with postgres 14, see the test result in dbfiddle.
The reason is explained in the PostGres 14 manual :
User-defined objects that reference certain built-in array functions along with their argument types must be recreated (Tom Lane)
Specifically, array_append(), array_prepend(), array_cat(), array_position(), array_positions(), array_remove(), array_replace(), and width_bucket() used to take anyarray arguments but now take anycompatiblearray. Therefore, user-defined objects like aggregates and operators that reference those array function signatures must be dropped before upgrading, and recreated once the upgrade completes.
To make it working, you can do instead :
CREATE OR REPLACE FUNCTION median(anycompatiblearray)
RETURNS float8 AS
$$
...
$$ LANGUAGE sql IMMUTABLE ;
...
CREATE AGGREGATE median(anycompatible) (
SFUNC=array_append,
STYPE=anycompatiblearray,
FINALFUNC=median,
INITCOND='{}'
);