Skip to content

Instantly share code, notes, and snippets.

@ambantis
Created October 1, 2013 19:48
Show Gist options
  • Save ambantis/6784040 to your computer and use it in GitHub Desktop.
Save ambantis/6784040 to your computer and use it in GitHub Desktop.
A Postgres function to flatten a one-to-many relationship to a one-to-one relationship of comma-delimited strings
SELECT DISTINCT
id, string_agg(child, ',' ORDER BY child) AS child_str
FROM children GROUP BY id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment