Re: Conversion from CHAR HEX

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Conversion from CHAR HEX
Date: 2014-05-27 15:36:42
Message-ID: 1401205002844-5805127.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

saqibrafique wrote
> hi guys,
> I am trying to convert a simple char value to HEX but I am getting Error.
>
*
> MyTable:
*
>
> CREATE TABLE mytable (from_ip CHAR(20), to_ip CHAR(20));
*
> I have below values in the Table:
*
>
>
> fm_db_Server1=# select * from operator;
> from_ip | to_ip
> --------------------+----------------------
> 202.153.087.128 | 202.153.087.159
> 196.192.015.000 | 196.192.015.063
> (2 rows)
>
>
> I am trying to extract the 1st part of the IP and convert to the HEX as
> below:
>
>
> fm_db_Server1=#
*
> select to_hex(to_number(substr(from_ip, 1, 3), '999')) as price from
> operator;
*
>
/
> ERROR: function to_hex(numeric) does not exist
> LINE 1: select to_hex(to_number(substr(from_ip, 1, 3), '999')) as p...
> ^
> HINT: No function matches the given name and argument types. You might
> need to add explicit type casts.
/
>
>
>
> I am not able to figure it out what is wrong here. Can Any body point out
> what is wrong here.
> Thanks is advance.

The error says that the function to_hex(numeric) does not exist.

Looking at the documentation the only to_hex function I found requires
either integer or bigint input.

Since numeric can be cast to integer/bigint the solution is simple.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Conversion-from-CHAR-HEX-tp5805115p5805127.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Louis Battuello 2014-05-27 15:50:46 Re: "Interrupt requested" in postgresql-DAY.log
Previous Message Shaun Thomas 2014-05-27 15:29:04 Re: Need pg_dump not to dump extension-created triggers