pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedStoring/sorting hex data in PostgreSQL
2+ messages / 2 participants
[nested] [flat]
* Storing/sorting hex data in PostgreSQL
@ 2009-07-20 19:59 JJ <jayson.prichard@comsouth.net>
2009-07-21 11:14 ` Re: Storing/sorting hex data in PostgreSQL nha <lyondif02@free.fr>
0 siblings, 1 reply; 2+ messages in thread
From: JJ @ 2009-07-20 19:59 UTC (permalink / raw)
To: pgsql-sql
I am parsing a map file and storing the hi, mid and low byte values of
symbol addresses in a comma separated value (.csv) file. I am then
importing this data into a PostgreSQL database with the copy
command.
The problem is that I want to sort and query the database based on the
hex addresses; from within another program using Npgsql (a .Net data
server for PostgreSQL).
How can I store hex values in PostgreSQL and sort and query them?
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Storing/sorting hex data in PostgreSQL
2009-07-20 19:59 Storing/sorting hex data in PostgreSQL JJ <jayson.prichard@comsouth.net>
@ 2009-07-21 11:14 ` nha <lyondif02@free.fr>
0 siblings, 0 replies; 2+ messages in thread
From: nha @ 2009-07-21 11:14 UTC (permalink / raw)
To: JJ <jayson.prichard@comsouth.net>; +Cc: pgsql-sql
Hello,
On 20/07/09 21:59, JJ wrote :
> [...]
> I want to sort and query the database based on the
> hex addresses [...]
> How can I store hex values in PostgreSQL and sort and query them?
>
PostgreSQL (since version 8.3 and maybe older) sets string functions for
encoding/decoding strings from/to their hexadecimal representation. The
following page presents these functions:
http://www.postgresql.org/docs/8.3/interactive/functions-string.html
For example:
# SELECT decode('6d61702064617461', 'hex');
results in string: map data
# SELECT encode('map data', 'hex');
results in hexadecimal representation of "map data": 6d61702064617461
(ie. each character [each byte in fact] is replaced by its hexadecimal
representation in ASCII range [space " " is replaced by "20" (hex.
value) or "32" (decimal value)])
A (simplier?) alternative would be to convert hexadecimal value into
text with the natural class operator:
# SELECT '6d61'::text;
results in string (text type): 6d61
At this time, I do not know about any PostgreSQL function that converts
from/to hex. to/from integer. Such functions may be user-created. The
sorting speed may then depend on the meaning of integer values (numeric
relation relevance) with your data.
Regards.
--
nha / Lyon / France.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2009-07-21 11:14 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-07-20 19:59 Storing/sorting hex data in PostgreSQL JJ <jayson.prichard@comsouth.net>
2009-07-21 11:14 ` nha <lyondif02@free.fr>
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