def batch_upsert_records(session, table, records):
if not records:<EOL><INDENT>return<EOL><DEDENT>for record_batch in _batch_postgres_query(table, records):<EOL><INDENT>stmt = insert(table.__table__)<EOL>stmt = stmt.on_conflict_do_update(<EOL>constraint=table.__table__.primary_key,<EOL>set_={<EOL>"<STR_LIT>": stmt.excluded.get("<STR_LIT>"),<EOL>"<STR_LIT>": stmt.excluded.get("<STR_LIT>"),<EOL>},<EOL>)<EOL>session.execute(stmt, record_batch)<EOL>session.commit()<EOL><DEDENT>
Batch upsert records into postgresql database.