I only recently realised that to_hex() converts its input to unsigned before converting it to hex (something that's not mentioned in the docs):
to_hex(-1) -> ffffffff I think that's something that some users might find surprising, especially if they were expecting to be able to use it to output values that could be read back in, now that we support non-decimal integer input. So I think the docs should be a little more explicit about this. I think the following should suffice: --- to_hex ( integer ) -> text to_hex ( bigint ) -> text Converts the number to its equivalent two's complement hexadecimal representation. to_hex(1234) -> 4d2 to_hex(-1234) -> fffffb2e --- instead of the existing example with 2147483647, which doesn't add much. I also think it might be useful for it to gain a couple of boolean options: 1). An option to output a signed value (defaulting to false, to preserve the current two's complement output). 2). An option to output the base prefix "0x" (which comes after the sign, making it inconvenient for the user to add themselves). I've also been idly wondering about whether we should have a numeric variant (for integers only, since non-integers won't necessarily terminate in hex, aren't accepted as inputs, and don't seem particularly useful anyway). I don't think two's complement output makes much sense for numeric, so perhaps it should only have the prefix option, and always output signed hex strings. Thoughts? Regards, Dean