I wanna return table. The function get an array(the query is 'select function_name(array_agg(column_name)) from table_name')
I coded below:
create type pddesctype as(
count float,
mean float,
std float,
min float
);
create function pddesc(x numeric[])
returns pddesctype
as $$
import pandas as pd
data=pd.Series(x)
count=data.describe()[0]
mean=data.describe()[1]
std=data.describe()[2]
min=data.describe()[3]
return count, mean, std, min
$$ language plpython3u;
This code results only array on one column. (float, float, float...)
I tried
create function pddesc(x numeric[])
returns table(count float, mean float, std float, min float)
as $$
import pandas as pd
data=pd.Series(x)
count=data.describe()[0]
mean=data.describe()[1]
std=data.describe()[2]
min=data.describe()[3]
return count, mean, std, min
$$ language plpython3u;
But there is an error:
ERROR: key "count" not found in mapping
HINT: To return null in a column, add the value None to the mapping with the key named after the column.
CONTEXT: while creating return value.
I want to show the result in columns (like a table) without creating type in advance.
How to change the RETURN / RETURNS syntax?
returns table (...)
– Pensionaryselect * from pddesc(...)
– Pensionaryselect * from (select pddesc(array_agg(column_name)) from table_name) as result
. However, I get array data on one column. Do you know another way to get table? – Eolande