def _batch_postgres_query(table, records):
if not records:<EOL><INDENT>return<EOL><DEDENT>POSTGRESQL_MAX = <NUM_LIT><EOL>preamble = (<EOL>"<STR_LIT>"<EOL>+ table.__tablename__<EOL>+ "<STR_LIT>"<EOL>+ "<STR_LIT:U+002CU+0020>".join(records[<NUM_LIT:0>].keys())<EOL>+ "<STR_LIT>"<EOL>+ "<STR_LIT:U+002CU+0020>".join(["<STR_LIT:?>"] * len(records[<NUM_LIT:0>].keys()))<EOL>+ "<STR_LIT>"<EOL>)<EOL>start = <NUM_LIT:0><EOL>end = <NUM_LIT:0><EOL>total_len = len(preamble)<EOL>while end < len(records):<EOL><INDENT>record_len = sum([len(str(v)) for v in records[end].values()])<EOL>end += <NUM_LIT:1><EOL>if total_len + record_len >= POSTGRESQL_MAX:<EOL><INDENT>logger.debug(f"<STR_LIT>")<EOL>yield records[start:end]<EOL>start = end<EOL>total_len = len(preamble)<EOL><DEDENT>else:<EOL><INDENT>total_len += record_len<EOL><DEDENT><DEDENT>yield records[start:end]<EOL>
Break the list into chunks that can be processed as a single statement.

    Postgres query cannot be too long or it will fail.
    See: https://dba.stackexchange.com/questions/131399/is-there-a-maximum-
     length-constraint-for-a-postgres-query

    :param records: The full list of records to batch.
    :type records: iterable
    :param table: The sqlalchemy table.
    :return: A generator of lists of records.