Has anyone found an efficient way to store BSON ObjectId values in an SQL database?
The range of a 12-byte unsigned int would be 0..79228162514264337593543950335
(29 digits max); according to docs (same URL you cited), a DECIMAL
/NUMERIC
column packs each group of nine base10 digits into four bytes (adding up to floor(29 / 9) * 4 = 3 * 4 = 12
bytes for the first 27 digits), with the remaining 2 digits taking an additional byte, coming up to 13 bytes of storage for a DECIMAL(29)
column.
Or, you can store them as BINARY(12)
.