Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

399
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda