First off, the iceberg-cube query is defined as in
Let's say I have a relation item,location,year,supplier,unit_sales
,
and I would like to write a plpgsql
functions as
a wrapper around the query in the image, to specify the parameter N
,
like so:
create or replace function iceberg_query( percentage integer )
returns cube
/* Code here */
as
$$
declare
numrows int;
begin
select count(*) into numrows from sales;
select item, location, year, count(*)
from sales
group by cube(item,location,year)
having count(*) >= numrows*percentage/100;
end;
$$ language 'plpgsql'
What do I need to add to Code here
-part, to make this work? How to specify a data cube as a return type in plpgsql
?