'Return the aggregate, rendered as SQL.'

def as_sql(self, qn, connection):

    if connection.ops.oracle:
        self.extra['tolerance'] = self.tolerance
    if hasattr(self.col, 'as_sql'):
        field_name = self.col.as_sql(qn, connection)
    elif isinstance(self.col, (list, tuple)):
        field_name = '.'.join([qn(c) for c in self.col])
    else:
        field_name = self.col
    (sql_template, sql_function) = connection.ops.spatial_aggregate_sql(self)
    params = {'function': sql_function, 'field': field_name}
    params.update(self.extra)
    return (sql_template % params)
