Данное выражение выполняется без ошибок
WITH table_columns AS (
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_schema = 'public'
)
SELECT
table_name, json_object_agg(column_name, data_type) as columns
FROM table_columns
GROUP BY table_name;
а вот это дает ошибку: ERROR: column "table_columns.column_name" must appear in the GROUP BY clause or be used in an aggregate function
WITH table_columns AS (
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_schema = 'public'
)
SELECT
table_name, json_build_object(column_name, data_type) as columns
FROM table_columns
GROUP BY table_name;
почему второй вариант дает ошибку? Я пробою вернуть json of lists {[ column_name, data_type ], [ column2_name, data_type2], ....}