Hex to Dec Conversion

Поиск
Список
Период
Сортировка
Искать
От
Donald Kerr
Тема
Hex to Dec Conversion
Дата
Msg-id
13D772956A774BD189329582C6ADE155@DELLM4500
Список
Дерево обсуждения
Hex to Dec Conversion "Donald Kerr" <donald.kerr@dkerr.co.uk>
Re: Hex to Dec Conversion Josh Kupershmidt <schmiddy@gmail.com>
Postgres Wishlist "Donald Kerr" <donald.kerr@dkerr.co.uk>
Re: Postgres Wishlist Steve Crawford <scrawford@pinpointresearch.com>
Re: Postgres Wishlist "Donald Kerr" <donald.kerr@dkerr.co.uk>
Re: Postgres Wishlist Tom Lane <tgl@sss.pgh.pa.us>
Re: Postgres Wishlist Steve Crawford <scrawford@pinpointresearch.com>
Re: Postgres Wishlist "Donald Kerr" <donald.kerr@dkerr.co.uk>
Re: Postgres Wishlist Michael Glaesemann <grzm@seespotcode.net>
Re: Postgres Wishlist Mladen Gogala <mladen.gogala@vmsinfo.com>
Re: Postgres Wishlist Mladen Gogala <mladen.gogala@vmsinfo.com>
Re: Postgres Wishlist Michael Wood <esiotrot@gmail.com>
Re: Postgres Wishlist "Donald Kerr" <donald.kerr@dkerr.co.uk>
Re: Postgres Wishlist Michael Wood <esiotrot@gmail.com>
Re: Postgres Wishlist "Donald Kerr" <donald.kerr@dkerr.co.uk>
Re: Postgres Wishlist "Donald Kerr" <donald.kerr@dkerr.co.uk>
Re: Postgres Wishlist Michael Glaesemann <grzm@seespotcode.net>
Re: Postgres Wishlist "Donald Kerr" <donald.kerr@dkerr.co.uk>
Re: Postgres Wishlist Mladen Gogala <mladen.gogala@vmsinfo.com>
Re: Hex to Dec Conversion "Donald Kerr" <donald.kerr@dkerr.co.uk>
My first post to the mailing list and I hope I am in the right place!

I am trying to convert from hex to decimal and can do that successfully
using the following code:

SELECT x'FF'::integer;

which outputs 255 and is exactly what I want.

I want to substitute the string in the code 'FF' for a column in the
database like so:

SELECT x'db_column'::integer FROM db_table;

but no matter the combinations I try, I cannot get it to work.

Thew data colum contains html color codes like "0099FF" and I want to
convert these to, in this case, "0 153 255".

The following code behaves well: 

SELECT  x'00'::integer || ' ' || x'99'::integer || ' ' ||  x'FF'::integer;

resulting in "0 153 255". All correct

I was hopeful that something similar to the following would work but I just
cannot get it to work despite trying various combinations.

SELECT x'substring(col,1,2)'::integer || ' ' ||
x'substring(col,3,2)'::integer || ' ' || x'substring(col,5,2)'::integer

I would much prefer to do this as part of the query rather than having to
create a function. There must be a way! :)

Any help would be very greatly apprecaited.

Regards,

Donald

В списке pgsql-novice по дате отправления
От: Thom Brown
Дата:
Сообщение: Re: database access
От: Josh Kupershmidt
Дата:
Сообщение: Re: Hex to Dec Conversion
FAQ