Re: Convert int to hex

Lists: pgsql-sql
From: Fernando Grijalba <fgrijalba(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Convert int to hex
Date: 2005-06-01 20:42:16
Message-ID: f817a44d050601134211d78731@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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


From: Richard Huxton <dev(at)archonet(dot)com>
To: Fernando Grijalba <fgrijalba(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Convert int to hex
Date: 2005-06-02 07:14:39
Message-ID: 429EB1DF.7060202@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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


From: Fernando Grijalba <fgrijalba(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Convert int to hex
Date: 2005-06-02 10:04:34
Message-ID: f817a44d050602030451270b0f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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(at)gmail(dot)com> wrote:
> On 6/1/05, Fernando Grijalba <fgrijalba(at)gmail(dot)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)
>