Replies: 2 comments
|
With all due respect, what does this question have to do with the SQLModel project? The docs make it very clear that this is a thin layer around the SQLAlchemy ORM. SQLModel changes nothing whatsoever about the underlying database query logic of SQLAlchemy. So if anything, this question might be related to SQLAlchemy. However, I would argue that this question is maybe not even ORM-related at all. You seem to have a very database-centered question and you even found a related question+answer completely independent of any underlying ORM. If I misunderstood your question, please do clarify, but I honestly don't think this is an appropriate place to ask this. My general advice: Abstraction. Boil down your example even further (stripping it of all specifics, unrelated fields etc., call the models/fields |
|
I am no python ORM expert (faaaar from it), and therefore was wondering if anyone had some feedback to share on the topic, and since |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Code
Description
I simplified the code as much as to focus on my interrogation. I have a simple one to many relation between Lei and Isin. Imagine that I am given new {lei: isins} values and I have to either insert or update the lei. My question is simple: should I commit once at the end or in the for loop just above ? or in the lei loop? Should I batch if I have 10M leis? Is the answer the same in Create and Upsert mode?
I found this related stackoverflow thread https://stackoverflow.com/questions/24377193/best-way-to-update-millions-of-records-in-sql-table-with-foreign-keys, which describes well what I am trying to accomplish, but the solution seems far fetched (buy maybe it is not?)
I can experiment all suggested ideas if needs be :)
Operating System
Linux
Operating System Details
python:3.10-slim docker image
Requirements.in (then converted to txt via pip-compile)
SQLModel Version
0.0.6
Python Version
3.10
Additional Context
In creation mode, a csv with 8 millions LEI/ISINS line takes less thant 30 minutes to insert. In upsert I gave up, it was too long with my naive implentation :)
All reactions