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

397
Vistas
PNG images in postgresql database

I would like to know how can I insert an image "bytea" into a table of my postgresql database, with the condition that the image must be a png file.

Here is the table:

"id_category" SERIAL,
"category_name" TEXT,
"category_image" bytea,
constraint id_cat_pkey primary key ("id_category"))without oids;

How can I ensure that any files inserted into the table must only be PNG files?

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

0

The best you can do is to write a check constraint that extracts the first few bytes from the bytea and checks for the appropriate magic number:

CHECK (substr(image, 1, 8) = BYTEA '\x89504E470D0A1A0A')

Of course there is no guarantee that no other file starts with these bytes, but that is the best you can do short of checking the whole file for consistency.

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