I am interested in the implementation or code of the stddev_pop() function. I understand what it does, I know there is a definition in the documentation, but I am interested in the code itself.
I tried to find it in pgAdmin within the public schema/functions and aggregates, but it’s not there. I also tried this query:
SELECT *
FROM pg_proc
WHERE proname = 'stddev_pop';
that gave me 6 different results. But when I try to query using the function’s oid, this is what happens:
SELECT pg_get_functiondef(2724);
ERROR: "stddev_pop" is an aggregate function
SQL state: 42809
Also in psql I tried:
isa=# df stddev_pop
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+------------+------------------+---------------------+------
pg_catalog | stddev_pop | numeric | bigint | agg
pg_catalog | stddev_pop | double precision | double precision | agg
pg_catalog | stddev_pop | numeric | integer | agg
pg_catalog | stddev_pop | numeric | numeric | agg
pg_catalog | stddev_pop | double precision | real | agg
pg_catalog | stddev_pop | numeric | smallint | agg
(6 rows)
but couldn’t get further.
How can I "look into" an aggregate function?
2
Answers
This is a built-in aggregate function. You will find the implementation in the postgres code base.
You have to query the
pg_aggregate
catalog:Those are just the basic attributes; see the documentation of
pg_aggregate
for the rest.If you need to get the
CREATE AGGREGATE
statement, you should usepg_dump
. However, there is no way to dump only a single function.