pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Convert int to hex
4+ messages / 3 participants
[nested] [flat]

* Convert int to hex
@ 2005-06-01 20:42  Fernando Grijalba <fgrijalba@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Fernando Grijalba @ 2005-06-01 20:42 UTC (permalink / raw)
  To: pgsql-sql

I want to be able to change an int4 from a sequence and store it as
varchar in the database as a hex number.

Is this possible?

Thank you,

Fernando



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Convert int to hex
@ 2005-06-02 07:14  Richard Huxton <dev@archonet.com>
  parent: Fernando Grijalba <fgrijalba@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Richard Huxton @ 2005-06-02 07:14 UTC (permalink / raw)
  To: Fernando Grijalba <fgrijalba@gmail.com>; +Cc: pgsql-sql

Fernando Grijalba wrote:
> I want to be able to change an int4 from a sequence and store it as
> varchar in the database as a hex number.
> 
> Is this possible?

Try the to_hex() function - in the "Functions and operators" chapter of 
the manual - "Strings" section.

-- 
   Richard Huxton
   Archonet Ltd



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Convert int to hex
@ 2005-06-02 09:17  Ramakrishnan Muralidharan <ramakrishnanm@pervasive-postgres.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Ramakrishnan Muralidharan @ 2005-06-02 09:17 UTC (permalink / raw)
  To: Fernando Grijalba <fgrijalba@gmail.com>; pgsql-sql

Hi,

  You can use to_hex() function to convert integer to hexa number. I have tried with a small example.

create table testing( id int4 , sHex varchar( 20 ) )

insert into testing( id ) values( 204678 );
insert into testing( id ) values( 2076876 );


update testing set sHex = ( cast( to_hex( id ) as varchar( 20 ) ) )

select * from testing

Id     | shex
-------|------
204678 | 31f86
2076876| 1fb0cc 

Regards,
R.Muralidharan

 

-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Fernando Grijalba
Sent: Thursday, June 02, 2005 2:12 AM
To: pgsql-sql@postgresql.org
Subject: [SQL] Convert int to hex


I want to be able to change an int4 from a sequence and store it as
varchar in the database as a hex number.

Is this possible?

Thank you,

Fernando

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Convert int to hex
@ 2005-06-02 10:04  Fernando Grijalba <fgrijalba@gmail.com>
  parent: Fernando Grijalba <fgrijalba@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Fernando Grijalba @ 2005-06-02 10:04 UTC (permalink / raw)
  To: pgsql-sql

Thank you, I found out after I posted the message.

I did read the docs but must have looked somewhere else and I search
the lists for hex only and it did not bring the answer back.  It
wasn't until I search for int4 to hex that I was able to find the
answer.

Thank you again.

Fernando

On 6/1/05, Tony Wasson <ajwasson@gmail.com> wrote:
> On 6/1/05, Fernando Grijalba <fgrijalba@gmail.com> wrote:
> > I want to be able to change an int4 from a sequence and store it as
> > varchar in the database as a hex number.
> >
> > Is this possible?
> >
> > Thank you,
> >
> > Fernando
> 
> Sure you can go from integer to hex and back...
> http://www.varlena.com/varlena/GeneralBits/104.php
> 
> Here's the example queries to get you started.
> 
>    =# select to_hex(11);
>     to_hex
>    --------
>     b
>    (1 row)
> 
>    =# select x'ab'::integer;
>     int4
>    ------
>      171
>    (1 row)
>



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2005-06-02 10:04 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-01 20:42 Convert int to hex Fernando Grijalba <fgrijalba@gmail.com>
2005-06-02 07:14 ` Richard Huxton <dev@archonet.com>
2005-06-02 10:04 ` Fernando Grijalba <fgrijalba@gmail.com>
2005-06-02 09:17 Re: Convert int to hex Ramakrishnan Muralidharan <ramakrishnanm@pervasive-postgres.com>

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