pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedparsing a string with a hexadecimal notation
4+ messages / 3 participants
[nested] [flat]
* parsing a string with a hexadecimal notation
@ 2005-02-09 11:01 KÖPFERL Robert <robert.koepferl@sonorys.at>
0 siblings, 1 reply; 4+ messages in thread
From: KÖPFERL Robert @ 2005-02-09 11:01 UTC (permalink / raw)
To: pgsql-sql
I intend to retrieve an int value in an integer variable from a string with
a hexadecimal notation of a number.
Which function is appropriate to do
i int4
i = ???('BEAF')
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: parsing a string with a hexadecimal notation
@ 2005-02-09 13:35 Achilleus Mantzios <achill@matrix.gatewaynet.com>
parent: KÖPFERL Robert <robert.koepferl@sonorys.at>
0 siblings, 1 reply; 4+ messages in thread
From: Achilleus Mantzios @ 2005-02-09 13:35 UTC (permalink / raw)
To: KÖPFERL Robert <robert.koepferl@sonorys.at>; +Cc: pgsql-sql
O KÖPFERL Robert Ýãñáøå óôéò Feb 9, 2005 :
> I intend to retrieve an int value in an integer variable from a string with
> a hexadecimal notation of a number.
> Which function is appropriate to do
> i int4
> i = ???('BEAF')
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.
E.g. in java:
String hex="FF";
st = con.prepareStatement("select int4(X'"+hex+"'::bit varying");
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
--
-Achilleus
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: parsing a string with a hexadecimal notation
@ 2005-02-09 20:51 Tom Lane <tgl@sss.pgh.pa.us>
parent: Achilleus Mantzios <achill@matrix.gatewaynet.com>
0 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2005-02-09 20:51 UTC (permalink / raw)
To: Achilleus Mantzios <achill@matrix.gatewaynet.com>; +Cc: KÖPFERL Robert <robert.koepferl@sonorys.at>; pgsql-sql
Achilleus Mantzios <achill@matrix.gatewaynet.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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: parsing a string with a hexadecimal notation
@ 2005-02-10 09:37 KÖPFERL Robert <robert.koepferl@sonorys.at>
0 siblings, 0 replies; 4+ messages in thread
From: KÖPFERL Robert @ 2005-02-10 09:37 UTC (permalink / raw)
To: ; +Cc: pgsql-sql
> 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
Thanks, that worked for me
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2005-02-10 09:37 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-09 11:01 parsing a string with a hexadecimal notation KÖPFERL Robert <robert.koepferl@sonorys.at>
2005-02-09 13:35 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
2005-02-09 20:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-02-10 09:37 Re: parsing a string with a hexadecimal notation KÖPFERL Robert <robert.koepferl@sonorys.at>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox