Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

620
Vistas
How to properly convert uuid to BINARY(16)?

I have an id field of type BINARY(16) in a mysql table.

I generate the following id: 66e2105c-bff5-4206-a9cc-e212f5622368

With this code:

const v = uuidV4Bytes(16);

The insert via sequalize is:

INSERT INTO SPORTS(Id,Name,HouseId,Date,Active)
        VALUES ('66e2105c-bff5-4206-a9cc-e212f5622368','SPORTNAME',1, '2020-05-04', 0)

Problem:

Error Code: 1406. Data too long for column 'Id' at row 

Im trying to convert a uuid to a binary(16) but apperently Im getting a value that is to big. How do I solve this?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Thanks to @hanshenrik I started searching for a way to use UNHEX in nodeexpress.

I found the following:

const byteValue = Buffer.from(uuidV4Bytes(16).replace('-', ''), 'hex')

This did the trick. However I can not say that this is the most optimal way but it solved my problem.

over 4 years ago · Santiago Trujillo Denunciar

0

as long as it's always in the form 8-4-4-4-12 hex characters, you could just have MySQL do it for you with REPLACE() and UNHEX()

INSERT INTO SPORTS(Id,Name,HouseId,WDate,Active)
    VALUES (UNHEX(REPLACE('66e2105c-bff5-4206-a9cc-e212f5622368','-','')),'SPORTNAME',1, '2020-05-04', 0)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda