1

In a PostgreSQL table I have a column file_bytes which has the data type bytea.

I am looking for a simple SQL statement to manipulate only the last byte of the content of this column.

André
  • 464
  • 4
  • 17
  • 1
    `set_byte()`? https://www.postgresql.org/docs/current/static/functions-binarystring.html –  Sep 28 '18 at 08:37

1 Answers1

2

demo: db<>fiddle

UPDATE test 
SET file_bytes = overlay(file_bytes placing 'X'::bytea from octet_length(file_bytes));

https://www.postgresql.org/docs/current/static/functions-binarystring.html

octet_length() gives the number of bytes of binary data. overlay() allows to rewrite data from a certain position.

S-Man
  • 22,521
  • 7
  • 40
  • 63