PostgreSQL:操作二进制数据 - 使用 SQL 命令更改最后一个字节

PostgreSQL: manipulate binary data - change last byte with SQL command

在 PostgreSQL table 中,我有一列 file_bytes,其数据类型为 bytea

我正在寻找一个简单的 SQL 语句来仅操作此列内容的最后一个字节。

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()给出二进制数据的字节数。 overlay()允许从某个位置改写数据。