Adds ability to use AUTO_INCREMENT
statement 🔭
#46435
Replies: 1 comment
-
Non of this methods are be thread safe. Consider two parallel requests, that do the same thing. Both are getting an auto-increment value of 5, both make further processing, and both are trying to use the same number, but only one will get this number. Next is that PostgreSQL have a different approach of for filling auto increment fields. The safer way is to insert a row with a stub value, get id from it, use it to make real value and perform update query. Of cause, there are rare cases where auto increment value could be helpfull (like php admin, that can show it to you). But my opinion, if you need some strange behavior, where you want to use AUTO INCREMENT directly it would be a good idea to write an ugly code, so it would be clear, that this code is not great, neither then hiding it in a glossy candy wrapper. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey Folks !
I was working on a scenario in which I have to get the next record
id
to use the result in the next process, let's see the next figure for more illuminationIf we need to get the next record
id
using Laravel, the code would beBut what if the table was empty, the max value would be
NULL
, so the result of the previous code will be1
, and It's an invalid value. When I searched for a solution to that issue I found thatMySQL
supports theAUTO_INCREMENT
statement to get a real value as shown in the next query.So what's your opinion about adding a feature for getting the real value using the
AUTO INCREMENT
statement?Beta Was this translation helpful? Give feedback.
All reactions