Skip to content
Advertisement

Efficient way to simultaneously calc AVG and stddev_pop in postgres

stddev_pop() must be calculating AVG() as part of the full calc of standard deviation (unless there’s a shortcut I’m unaware of).

for context, the goal is to test for the difference of means between the these two geom columns.

Is there any way to access that in order to avoid recalculating AVG()?

here’s an example query:

and the output of EXPLAIN ANALYZE which makes me think that if I ask for avg() and stddev_pop() it will only do the avg() calc once and reuse it?:

explain analyze

Advertisement

Answer

To combine both tables in a single result you must aggregate before joining:

or to get one row per table:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement