my prior experience: - find_or_create does not work - rescuing RecordNotUnique - can deadlock mysql - behaves differently across mysql and postgres transaction semantics so you still need db-specific code e.g. savepoints
-
-
Replying to @mountain_ghosts @samphippen
I know they added some alternate form of this, which is just broken in a different way (INSERT and then SELECT on failure), and an actual upsert API
1 reply 0 retweets 0 likes -
Replying to @mountain_ghosts
Hey
@sgrif I'm sure you know about these things, would you care to weigh in?2 replies 0 retweets 0 likes -
Replying to @penelope_zone @samphippen and
Literally all I want is find_or_create_by to do an `on duplicate update` in postgres.
1 reply 0 retweets 3 likes -
"find or create" and "create or update" are different operations though
1 reply 0 retweets 1 like -
There’s also create or find by
1 reply 0 retweets 0 likes -
Replying to @penelope_zone @samphippen and
yeah I think that's the thing that does INSERT and then SELECT if that fails
1 reply 0 retweets 0 likes -
yup
1 reply 0 retweets 0 likes -
Replying to @penelope_zone @samphippen and
That also has a race condition where a DELETE can occur between INSERT and SELECT
1 reply 0 retweets 0 likes -
Replying to @pixeltrix @samphippen and
Yup, which is really the best you can do unless you're willing to change your application logic. Repeatable read isolation level (serializable on non-pg) + find_or_create_by is what folks want, but that requires being ready to handle serialization failures
1 reply 0 retweets 1 like
You can also have a delete run after your select but before the data is displayed to the user. That one's even worse since you can't really detect it. Have to just be able to handle concurrent deletes or be willing to ignore it, no way around it
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.