Function string_agg() postgresql data base

Is there any way that a loop can create over query so multiple records can be set separated with comma?