I would like to convert the hexadecimal string used by HTML to bigint , then convert it to the individual values ββof R, G and B in Postgres through a function written in PL / pgSQL.
I can decode a string in bytea as follows:
hex bytea := decode(hex, 'hex');
And in a query with fixed values, this works like a beauty:
select ( array[ (cast(x'ffaa33' as bigint) >> 16) % 256, (cast(x'ffaa33' as bigint) >> 8) % 256, cast(x'ffaa33' as bigint) % 256 ] )
But I can not put these two together, passing, for example, "ffaa33" as a parameter.
Has anyone got a better idea? Am I using PosgreSQL 9.1?
source share