[pgsql-jp: 27870] Re: 16進数文字列を数値にする方法はありますか?
SATO Hiroyuki
hiroyuki @ navitime.co.jp
2002年 11月 2日 (土) 21:16:59 JST
佐藤です。
返信ありがとうございます。
ご提案いただいた方法では2文字までしか駄目なのかもしれません。
----(↓ここからログ↓)----
postgres=# select*from t;
hex
------
ff
fff
ffff
(3 rows)
postgres=# select get_byte(decode(hex,'hex'),0)from t;
ERROR: Bad hex code: ' '
postgres=# select get_byte(decode(hex,'hex'),0)from t where hex='ff';
get_byte
----------
255
(1 row)
postgres=# select get_byte(decode(hex,'hex'),0)from t where hex='fff';
ERROR: Bad hex code: ' '
postgres=# select get_byte(decode(hex,'hex'),0)from t where hex='ffff';
get_byte
----------
255
(1 row)
----(↑ここまでログ↑)----
From: ISHIDA Akio <iakio @ pjam.jpweb.net>
Subject: [pgsql-jp: 27869] Re: 16進数文字列を数値にする方法はありますか?
Date: Sat, 2 Nov 2002 20:56:52 +0900
> > 例えば次のようなデータです。
> > ----(↓ここから↓)----
> > postgres=# \d t
> > Table "t"
> > Column | Type | Modifiers
> > --------+--------------+-----------
> > hex | character(4) |
> >
> > postgres=# select*from t;
> > hex
> > ------
> > ff
> > (1 row)
> > ----(↑ここまで↑)----
>
> pg_proc を見てたら get_byte というのを見つけたので、
> なんか強引ですが、こんな方法でできるかもしれません。
>
> ishida=> select get_byte(decode('ff', 'hex'), 0);
> get_byte
> ----------
> 255
> (1 row)
pgsql-jp メーリングリストの案内