Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created August 24, 2013 20:18
Show Gist options
  • Save rightfold/e37f5bf7e38cad4e996d to your computer and use it in GitHub Desktop.
Save rightfold/e37f5bf7e38cad4e996d to your computer and use it in GitHub Desktop.
SELECT p.id, p.name, array_to_json(array_agg(gp.group_id)) AS group_ids
FROM permissions AS p
LEFT JOIN group_permissions AS gp
ON gp.permission_id = p.id
GROUP BY p.id
ORDER BY p.name ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment