Array pl / pgsql as input to aggregate function

I am writing a pl / pgsql function that does some statistics processing. using 8.2 postgres. I want to use this convenient aggregate function:

regr_slope (Y, X)

but I have X and Y data stored as local arrays in the pl / pgsql function: y double precision []; x double precision [];

Problem

is that I use this as a string in the pl / pgsql function:

slope: = regr_slope (y, x);

I get a message that the function is unavailable or has invalid arguments. I suspect this because the inputs should be selected as columns from a table instead of passing in double precision arrays.

Is there any way to make regr_slope function with local arrays? (i.e. how to pass an array as a valid input for an aggregate function?)

thank.

+3
source share
1 answer
SELECT regr_slope(x,y) INTO slope FROM (SELECT unnest(ARRAY[1,2,3,4]) as x, unnest(ARRAY[5,6,7,8]) AS y) AS z;
+1
source

Source: https://habr.com/ru/post/1771105/


All Articles