私は、この作品理由を理解しようとしています:巣PostgreSQLの
select
array_to_json(array_agg(row_to_json(positions_table)))
from (
select
sum(start_month),
function_id,
profile_id
from positions as subquery
group by function_id, profile_id
) as positions_table
しかし、これはしていません:
select
profiles.id,
(array_to_json(array_agg(row_to_json(
select
sum(start_month),
function_id,
profile_id
from positions as subquery
group by function_id, profile_id
))))
from profiles
それはそうです私はselect...
の文をarray_to_json(array_agg(row_to_json()))
の中に入れることが許されておらず、代わりにテーブルを参照する必要があるようです。
しかし、私は何かが不足している可能性が疑わしいです。
エラーはsyntax error near select
です。
FYI:3回のデータ変換(json、array、json)ではなく、代わりに希望の結果を得るために 'jsonb_agg()'を使うべきです[もっと見る](https://www.postgresql.org/docs/9.6/ static/functions-aggregate.html)。また、 'row_to_json'は' record'を入力として期待していますが、サブクエリはレコードのレコードではないので、N行を変換するために1行をjsonに変換することは期待できません。 –