Skip to content

Instantly share code, notes, and snippets.

@mistificator
Last active October 4, 2018 13:38
Show Gist options
  • Save mistificator/5b11909e3e8ee1305afc31984992acf0 to your computer and use it in GitHub Desktop.
Save mistificator/5b11909e3e8ee1305afc31984992acf0 to your computer and use it in GitHub Desktop.
Accum in array with relation values got from SELECT
SELECT DISTINCT
schedule_groups.id,
schedule_groups.description,
schedule_groups.groups_id,
array_agg(groups.id),
array_to_string(
ARRAY(
SELECT DISTINCT * FROM unnest(
array_accum(
ARRAY(
SELECT kls_modes.short_name_rus
FROM kls_modes
WHERE kls_modes.id = ANY(groups.work_mode_id)
)
)
)
),
', ')
FROM schedule_groups
INNER JOIN groups ON groups.id = ANY(schedule_groups.groups_id)
GROUP BY schedule_groups.id ORDER BY schedule_groups.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment