Re: parsing a string with a hexadecimal notation

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
Cc: KÖPFERL Robert <robert(dot)koepferl(at)sonorys(dot)at>, pgsql-sql(at)postgresql(dot)org
Subject: Re: parsing a string with a hexadecimal notation
Date: 2005-02-09 20:51:01
Message-ID: 20086.1107982261@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com> writes:
> You can do something like

> foodb=# SELECT int4(X'FF'::bit varying);
> int4
> ------
> 255
> (1 row)

> but i suspect you must prepare your statement out of sql.

No, I think you could do it with a placeholder if you wanted. The
secret is the (poorly documented) external syntax for a hex bit string:

regression=# select 'xBEEF'::bit varying;
varbit
------------------
1011111011101111
(1 row)

So it should work to do "SELECT int4($1::bit varying)" and then pass
'xBEEF' as the string value for the parameter.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ing. Jhon Carrillo 2005-02-09 20:57:14 Function .. AS..?
Previous Message John DeSoi 2005-02-09 15:06:53 Re: How to iterate through arrays?