Re: isnumeric(varchar) by psql

From: Venky Kandaswamy <venky(at)adchemy(dot)com>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>, "emilu(at)encs(dot)concordia(dot)ca" <emilu(at)encs(dot)concordia(dot)ca>
Subject: Re: isnumeric(varchar) by psql
Date: 2013-11-27 21:54:22
Message-ID: ac3529b8c58344cb803db286743344b7@BY2PR05MB237.namprd05.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Depends on what you want to really do. You can simply cast the field to numeric ( col::numeric) and it will convert it - or fail if it cannot.
On the other hand, if you do not want it to fail on non-numeric data, then just write a simple function that converts if it can or returns null if not.

________________________________________

Venky Kandaswamy

Principal Engineer, Adchemy Inc.

925-200-7124

________________________________________
From: pgsql-sql-owner(at)postgresql(dot)org <pgsql-sql-owner(at)postgresql(dot)org> on behalf of Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
Sent: Wednesday, November 27, 2013 1:46 PM
To: pgsql-sql
Subject: [SQL] isnumeric(varchar) by psql

Hello,

Does psql provide a function isnumeric(varchar) to check if a varchar
can be converted to a numeric field?

E.g.,
x | isnumeric
----------+-----------
| f
. | f
.0 | t
0. | t
0 | t
1 | t
123 | t
123.456 | t
abc | f
1..2 | f
1.2.3.4 | f
1x234 | f
1.234e-5 | t

Thanks a lot
Emi
--
Found examples users created by self. If psql provides similar one already?

--
Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message seikath 2013-12-02 09:49:51 Re: tab delimiter in output
Previous Message Emi Lu 2013-11-27 21:46:12 isnumeric(varchar) by psql