In your C++ code you have not bothered to check if the query prepared or executed OK. You have not looked at any error message that might be returned. You have not told us what, if anything, actually made it into the database. Not much we can do with this.
INSERT INTO test values ('137138');
But data in psql is stored has
byte 0=1
byte 1=3
byte 2=7...
..
..
byte5=8.
INSERT INTO test values ('137138');
But data in psql is stored has
byte 0=1
byte 1=3
byte 2=7...
..
..
byte5=8.
To copy to clipboard, switch view to plain text mode
Postgresql has stored what you asked it to store: the characters '1', '3', '7', '1', '3', '8' (that is bytes with values 49, 51, 55, 49, 51, 56 at a guess)
In your original post you are providing '137138' to decode() and telling it that it was hex, i.e. bytes 0x13, 0x71, and 0x38.
If you want two bytes with decimal value 137 and 138 then give it two bytes with something like these:
INSERT INTO test values (decode('898a', 'hex'));
INSERT INTO test values (decode('\211\212', 'escape'));
INSERT INTO test values (E'\\x898a');
INSERT INTO test values (E'\211\212');
INSERT INTO test values (decode('898a', 'hex'));
INSERT INTO test values (decode('\211\212', 'escape'));
INSERT INTO test values (E'\\x898a');
INSERT INTO test values (E'\211\212');
To copy to clipboard, switch view to plain text mode
Bookmarks