I select data from temporary table:
CREATE TEMPORARY TABLE IF NOT EXISTS "tmp"
(
"fuel_type" TEXT,
"litres" NUMERIC(8,2),
"is_rent" BOOLEAN
);
insert into tmp values ('petrol', 10, False);
insert into tmp values ('petrol', 20, False);
insert into tmp values ('diesel', 20, False);
Like this:
SELECT
(SELECT row(fuel_type, SUM(litres))
FROM tmp
GROUP BY fuel_type);
In case there more than one fuel_type
in tmp
, I get this error:
SQL Error [21000]: ERROR: more than one row returned by a subquery used as an expression
I expect this output
ARRAY_AGG
fuel_type|litres
petrol,40
diesel,20
2
Answers
The way your query was constructed was the issue. Try this below code instead to get the expected output.
It is not clear what realy is your expected result. Select comand results with rows and columns when data was found. From your expected result I could not (without reasonable doubt) conclude was it one or two rows nor one or two columns (putting aside unexplained ARRAY_AGG above it).
See the fiddle here.