0

When I select bytea fields filled with binary data in my Postgres database using the HDBC-postgreSQL driver (version 2.3.2.3), they come out as:

SqlByteString "\x<hex representation of binary data>"

That is, it returns a ByteString which contains a string containing \x followed by the hex representation of my binary data. This is inconvenient, dreadfully inefficient and basically makes no sense to me.

Is there any reason why it doesn't return a SqlByteString containing a byte string with the actual binary data inside it? Is there something I am missing, or how do I configure the driver to do that?

thanks

4

2 回答 2

1

我已经解决了这个到 postgresql.conf 并添加:

bytea_output = 'escape' #by default, it's 'hex'

这个剂量是它现在可以完全按照您插入它的方式检索数据,因为输出不再被编码。

我知道已经很晚了,我也是 Stack Overflow 的新手,但我教导说这些信息很重要。

于 2016-09-14T15:05:18.647 回答
1

这是这个库的一个长期已知问题。例如,请参阅此错误

更广泛的问题是获取原始字节需要相当多的聪明才智,而 postgres api 并不明显。您必须使用二进制而不是文本输出来调用整个查询(无论如何,这可以说更好,但需要重写绑定层的那部分)。

您可以看到调用 pqexecparams 的位置并注意它是使用最后一个参数 0 调用的,这在postgres 文档中意味着所有内容都以文本形式返回。对于 postgres,这意味着你看到的这个有趣的十六进制表示。

如果将该参数交换为 1,则可以更有效地完成工作(包括获取bytea字段的原始二进制文件),但Statement.hsc必须普遍重写以反序列化这些二进制值。

这是其中一件让很多人有点恼火的事情,但还没有人有足够的动力去重写和调试整个事情。但是,当然,有人真的应该!:-)

于 2016-03-18T06:58:20.910 回答