def _populate_median_table(self, median_table, metadata, connection, filter_values):
        origin_table = metadata.tables[self.table_name]
        origin_column = origin_table.c[self.key]

        query = select([cast(origin_column, Float(2))]).where(origin_column != '')
        for group in self.group_by:
            column = origin_table.c[group]
            query.append_column(column)
            query.append_order_by(column)

        query.append_order_by(origin_table.c[self.key])


        # TODO: better way of escaping names
        columns = ["value"] + self.group_by
        for i, c in enumerate(columns):
            columns[i] = '"%s"' % c

        from_select = InsertFromSelect(median_table, query, columns)

        logger.debug("Populate median table")
        connection.execute(from_select, **filter_values)
INSERT INTO temp_median (user_name, value) (
dataset/ETHPy150Open dimagi/commcare-hq/custom/world_vision/custom_queries.py/CustomMedianQueryMeta._populate_median_table