def wrap_with_agg_array(arel_or_rel_query, alias_name, casting_option = :agg, distinct = false)
      query          = group_when_needed(arel_or_rel_query)
      query          = Arel::Nodes::ArrayAgg.new(to_sql_array(query))
      query.distinct = distinct || [:agg_distinct, :array_agg_distinct].include?(casting_option)
      nested_alias_escape(query, alias_name)
    end
def wrap_with_agg_array(arel_or_rel_query, alias_name, casting_option = :agg, distinct = false)
      query          = group_when_needed(arel_or_rel_query)
      query          = Arel::Nodes::ArrayAgg.new(to_sql_array(query))
      query.distinct = distinct || [:agg_distinct, :array_agg_distinct].include?(casting_option)
      nested_alias_escape(query, alias_name)
    end
Wraps query into an aggregated array
 EX: `(ARRAY_AGG((SELECT * FROM users)) AS "members"`
     `(ARRAY_AGG(DISTINCT (SELECT * FROM users)) AS "members"`
     `SELECT ARRAY_AGG((id)) AS "ids" FROM users`
     `SELECT ARRAY_AGG(DISTINCT (id)) AS "ids" FROM users`