So i'm trying to convolute multiple queries and form the result as
[
{
heading: 'Test',
subheading: 'SubTest',
pItems: [
{
pid: 1,
product_name: 'Random Product',
stock: 500
},
{
pid: 1,
product_name: 'Random Product',
stock: 500
}
]
},
{
heading: 'Test 2',
subheading: 'SubTest 2',
pItems: [
{
pid: 1,
product_name: 'Random Product 2',
stock: 500
},
{
pid: 1,
product_name: 'Random Product 2',
stock: 500
}
]
}
]
Here is what i tried
https://dbfiddle.uk/?rdbms=postgres_10&fiddle=af81919b853b571ca2f25c96abbad596
But i'm getting this error
ERROR: aggregate function calls cannot be nested