Working in postgreSQL 9.6:
I have a number of select statements which are each outputting a single row
e.g. select 8 as "ColA", select 20 as "ColB", select 13 as "ColC"
And I need to get these into an array such as:
["ColA",8],["ColB",20],["ColC",13]
I've tried many varieties of row_to_json, array_to_json etc and no joy, can anybody help please?
The actual code I have tried is a bit more complicated than described above but the structure of the data is not... here is my existing code (just to show that I have
SELECT "JobTitle" "name",
(
select array_to_json(array_agg(row_to_json(d2))) from
(SELECT
(select row_to_json(d2_1) from (select SUM(CASE WHEN "StartDateTime"<(_Date_For + '1 hour'::interval) AND "EndDateTime">(_Date_For) THEN "Effect" ELSE 0 END) "00:00" from "tmpDashboardData" where "JobTitle"=x."JobTitle") d2_1)
UNION ALL
(select row_to_json(d2_10) from (select SUM(CASE WHEN "StartDateTime"<(_Date_For + '11 hour'::interval) AND "EndDateTime">(_Date_For + '10 hour'::interval) THEN "Effect" ELSE 0 END) "10:00" from "tmpDashboardData" where "JobTitle"=x."JobTitle") d2_10)
UNION ALL
(select row_to_json(d2_11) from (select SUM(CASE WHEN "StartDateTime"<(_Date_For + '12 hour'::interval) AND "EndDateTime">(_Date_For + '11 hour'::interval) THEN "Effect" ELSE 0 END) "11:00" from "tmpDashboardData" where "JobTitle"=x."JobTitle") d2_11)
) d2
) as "data"
FROM "tmpDashboardData" x GROUP BY "JobTitle"
Thanks Fdavidov I worked this one out eventually... here is my code for information: