Convert hex string to bigint in Postgres [duplicate]
This question already has an answer here: Convert hex in text representation to decimal number 5 answers I'd like to convert a hex string as used by HTML into a bigint to then convert it into separate R, G and B values in Postgres via a function written in PL/pgSQL. I can decode the string into bytea like this: 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't put the two together, passing - for example