2 ms·
Why doesn't Django try to do an UPDATE using the non-NULL primary key and look at the number of updated rows (which is returned by all the SQL databases I know)
by DrJokepu 17y ago
Why doesn't Django try to do an UPDATE using the non-NULL primary key and look at the number of updated rows (which is returned by all the SQL databases I know) and if it's zero only then do an INSERT? This way it would only have to do two queries for inserts and still remain idiot-safe. An UPDATE using the primary key that can't find any rows consumes the same amount of resources as a SELECT.
(This approach would cause problems with funny black magic triggers but funny black magic triggers cause problems anyway)