Back

postgres - 显示bytea 的值 : 使用 convert_from(column_name, 'UTF8') convert bytea, binary

发布时间: 2022-09-29 00:09:00

refer to:
https://dba.stackexchange.com/questions/273044/how-to-convert-a-bytea-column-to-text

快速回答:

假设 tx_hash是你的某个表的列(bytea)

select id, encode(tx_hash::bytea, 'escape') , tx_status, height from your_table;

这里就会返回结果了。

下面是其他回答:

SELECT id, convert_from(address_hash, 'UTF8') FROM public.addresses ORDER BY id DESC LIMIT 100

之前:

之后:

where 查询:

xxx=# select id, encode(code_hash, 'hex') from udts where id = 1195;
  id  |                              encode
------+------------------------------------------------------------------
 1195 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4
(1 row)

带上where 查询 bytea:

xxx=# select id, encode(code_hash, 'hex') from udts where code_hash = decode('c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4', 'hex');
   id   |                              encode
--------+------------------------------------------------------------------
   1195 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4
   1194 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4
   1203 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4
  11267 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4
   2116 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4
  11437 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4
   2090 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4
  19323 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4
  11441 | c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4

Back