PostgreSQL query to return results as a comma separated list
You can use the array() and array_to_string() functions togetter with your query.
With SELECT array( SELECT id FROM table );
you will get a result like: {1,2,3,4,5,6}
Then, if you wish to remove the {} signs, you can just use the array_to_string() function and use comma as separator, so: SELECT array_to_string( array( SELECT id FROM table ), ',' )
will get a result like: 1,2,3,4,5,6
SELECT string_agg(id::text, ',') FROM table
Requires PostgreSQL 9.0 but that's not a problem.