PL/R - 将整列作为参数传递
PL/R - Pass entire column as an argument
我正在尝试编写一个简单的 PL/R 函数来查找列的平均值 (Greenplum 4.3.4 DB)
CREATE OR REPLACE FUNCTION mean_plr(val numeric[]) RETURNS numeric AS
$$
x <- val
avg = mean(x)
return(avg)
$$
LANGUAGE 'plr';
SELECT mean_plr(sensor1) FROM public.tempSensors;
然而,这给了我错误:
ERROR: function mean_plr(numeric) does not exist
LINE 1: SELECT mean_plr(sensor1) FROM public.tempSensors;
^
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
弄清楚我做错了什么。 mean_plr(sensor1) 一次发送 1 个值。要发送整列,我们需要使用 array_agg() 函数。
SELECT mean_plr(array_agg(sensor1::numeric)) FROM public.tempSensors;
我正在尝试编写一个简单的 PL/R 函数来查找列的平均值 (Greenplum 4.3.4 DB)
CREATE OR REPLACE FUNCTION mean_plr(val numeric[]) RETURNS numeric AS
$$
x <- val
avg = mean(x)
return(avg)
$$
LANGUAGE 'plr';
SELECT mean_plr(sensor1) FROM public.tempSensors;
然而,这给了我错误:
ERROR: function mean_plr(numeric) does not exist
LINE 1: SELECT mean_plr(sensor1) FROM public.tempSensors;
^
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
弄清楚我做错了什么。 mean_plr(sensor1) 一次发送 1 个值。要发送整列,我们需要使用 array_agg() 函数。
SELECT mean_plr(array_agg(sensor1::numeric)) FROM public.tempSensors;