Reputation: 451
How to insert hex value like \x320000000d2f2100 in escape format into bytea field ?
bytea_output settings set to escape
Upvotes: 1
Views: 2606
Reputation: 324275
The bytea_output
setting has nothing to do with how bytea is interpreted by the server, only how it's sent to the client.
Do you want to insert the literal string \x320000000d2f2100
(as 7-bit ascii), i.e. producing the bytes 0x5c 0x78 0x33 0x32 0x30 0x30 0x30 0x30 0x30 0x30 0x30 0x64 0x32 0x66 0x32 0x31 0x30 0x30
?
If so, escape the backslash, as documented in the syntax for escape
format bytea literals.
regress=> SELECT BYTEA '\\x320000000d2f2100';
bytea
----------------------------------------
\x5c7833323030303030303064326632313030
(1 row)
Do you want to insert the bytes 0x32 0x00 0x00 0x00 0x0d 0x2f 0x21 0x00
, i.e. the hex value? If so, don't escape the backslash. It doesn't matter what the setting of bytea_output
is.
regress=> SELECT BYTEA '\x320000000d2f2100';
bytea
--------------------
\x320000000d2f2100
(1 row)
Upvotes: 3