Is it more efficient to do SELECT and compare in Java or DELETE and INSERT
0
votes
1
answer
180
views
I am hitting a **REST API** to get data from a service. I transform this data and store it in a database. I will have to do this on some interval, 15 minutes, and then make sure this database has latest information.
I am doing this in a Java program. I am wondering if it would be better, after I have queried all data, to do:
1. **SELECT** statements and compare vs transformed data and do **UPDATEs** (**DELETE** all associated records to what was changed and **INSERT** new)
**OR**
2. **DELETE ALL** and **INSERT ALL** every time.
Option 1 has potential to have a lot less transactions, guaranteed SELECT on all records because we are comparing, but potentially not a lot of UPDATEs since I don't expect data to be changing much. But it has downside of doing comparisons on all records to detect a change.
I am planning on doing this using Spring Boot, JPA layer and possibly Postgres
Asked by user137760
(1 rep)
Nov 1, 2017, 06:02 PM
Last activity: Jul 10, 2025, 01:16 PM
Last activity: Jul 10, 2025, 01:16 PM