要向数据中写入一个字节的数据,应该使用该字节的8进制进行写入
如:“}”的ASCII码为“125(10进制)” 对应的8进制为“175”
注意:如果10进制转换为8进制没有三位的应该在前面补0
如:“=”的ASCII码为“61”对对应的8进制为“75” 应该写成‘\075’ 而不是‘\75’
八进制写入:
update dj_data SET data_content='\175\175'::bytea where terminal_id='321'
十六进制写入:
在PostgreSQL 9.0 中引入了十六进制格式 ;早期版本和一些工具不理解它
update dj_data SET data_content=E'\\xe4bda0e5a5bd313233'::bytea where terminal_id='321'
读取:
select encode(data_content,'hex'),data_content from dj_data where terminal_id='321';
python从文件读取:
python从文件写入:
参考:https://www.postgresql.org/docs/9.2/static/datatype-binary.html
https://www.yiibai.com/manual/postgresql/datatype-binary.html