We are generating an ordered uuid as a primary key in our tables to prevent duplicate primary keys on replication of our database servers. Is there a way to obtain the value of the primary key field (or the generated ordered uuid) upon insert without running a second query?
We have tried getting the value with the ".insertId" on the result set that it returns but that only works with auto incrementing primary keys so the insertId is always being returned as "0".
Is there a way to obtain the value of the primary key field (or the generated ordered uuid) upon insert without running a second query?
Here is the result object I get back:
OkPacket {
fieldCount: 0,
affectedRows: 1,
insertId: 0,
serverStatus: 2,
warningCount: 0,
message: '',
protocol41: true,
changedRows: 0
}
With an auto incrementing primary key, the "insertId" is the primary key. But since we aren't using auto increment, it stays at 0.
The short answer is “No”, however, accept my answer at your own discretion.