I read the sqlalchemy documentation, but some nuances escape me.
Is the code
session.add(item) session.commit() equivalent code
session.merge(item) ?
If not - what's the difference? If so, can I, instead of a large number of merge, use the same number of add, and then one general commit? Do I understand correctly that in this case one sql query will actually be executed instead of a set, and this will save execution time?
If so, after what number add should commit?
The fact is that I now support someone else's code. In it, tens of thousands of new items are created in cycles, which need to be added (or updated if lines already exist with the same primary key) into the database, and the script takes two to three hours. Can I expect to speed up after replacing merge with add + commit? Could this lead to unexpected problems?
Database on PostgreSQL, if that matters.