I am trying to replicate some java code in Postgres.
The operation, I need to perform is to convert Java BigInteger
to byte array
Java Code:
public class Main {
public static void main(String[] args) {
BigInteger n = new BigInteger("1677259342285725925376");
System.out.println(Arrays.toString(n.toByteArray()));
}
}
Output: [90, -20, -90, 53, 78, -38, 2, -128, 0]
Postgres Code:
select numeric_send(1677259342285725925376);
Output: "\000\006\000\005\000\000\000\000\000\020\036-$~\013)\012 \025\000"
Used numeric_send
to convert numeric to bytea
http://www.leadum.com/downloads/dbscribe/samples/postgresql/web_modern/function/main/643567399.html
To check output as in Java Console, I wrote below anonymous block
do
$$
declare
bytes bytea;
begin
bytes := numeric_send(1677259342285725925376);
for i in 0..length(bytes)-1 loop
raise notice '%', get_byte(bytes,i);
end loop;
end; $$
Now output printed as:
NOTICE: 0
NOTICE: 6
NOTICE: 0
NOTICE: 5
NOTICE: 0
NOTICE: 0
NOTICE: 0
NOTICE: 0
NOTICE: 0
NOTICE: 16
NOTICE: 30
NOTICE: 45
NOTICE: 36
NOTICE: 126
NOTICE: 11
NOTICE: 41
NOTICE: 10
NOTICE: 32
NOTICE: 21
NOTICE: 0
According to me output should be same as I am converting along to byte array in both. Please help how can I achieve the same.
Thanks