在PostgreSQL 8.4中可以将多个整数(int4)值连接到byte值吗?
例如:
5::int4 || 1::int4假设使用一个小的endian机器,应该会产生一个带有(0x05 0x00 0x00 0x00 0x01 0x00 0x00 0x00)的byte值。
发布于 2012-01-13 04:59:25
嗯,int4send会将int4转换为bytea,但我怀疑从名称上看,它将始终使用网络排序。
这就是:
steve@steve@[local] =# select int4send(3);
int4send
------------
\x00000003事件发生在amd64计算机上。
发布于 2012-01-13 05:13:05
可以使用select byteain(bit_out(5::bit(32) || 1::bit(32)))或select int4send(5)||int4send(1)进行间接转换,从而生成0000000000000000000000000000010100000000000000000000000000000001。
您还可以使用binary string functions将其转换为所需的编码。有关类似问题的解决方案,请参阅pgsql-general列表中的Maarten Foqué's answer。您应该能够简单地连接来自他的函数或类似函数的结果bytea值(但将其标记为稳定而不是易失性)。
https://stackoverflow.com/questions/8840156
复制相似问题