Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

decode hex in PostgreSQL - got error "odd number of digits"

Tags:

postgresql

I have a problem using this query:

select decode(to_hex(ascii('ل')::int),'hex')

When I execute it, I get:

ERROR: invalid hexadecimal data: odd number of digits
like image 932
Thessa Avatar asked Oct 26 '25 11:10

Thessa


1 Answers

decode(..., 'hex') doesn't mean convert this hexadecimal number to something. Hex encoding is a particular encoding format for bytes, and it requires two hexadecimal digits per octet. On the other hand, to_hex converts an integer to a hexadecimal representation, and that could have an even or odd number of digits.

So the answer is, you can't do that (without some manual fixups). And it's not clear why you would want to, either. It looks like you could just do 'ل'::bytea, but that might not be what you wanted either.

like image 58
Peter Eisentraut Avatar answered Oct 29 '25 02:10

Peter Eisentraut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!