agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
isnumeric(varchar) by psql
2+ messages / 2 participants
[nested] [flat]

* isnumeric(varchar) by psql
@ 2013-11-27 21:46 Emi Lu <emilu@encs.concordia.ca>
  2013-11-27 21:54 ` Re: isnumeric(varchar) by psql Venky Kandaswamy <venky@adchemy.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Emi Lu @ 2013-11-27 21:46 UTC (permalink / raw)
  To: pgsql-sql

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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



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

* Re: isnumeric(varchar) by psql
  2013-11-27 21:46 isnumeric(varchar) by psql Emi Lu <emilu@encs.concordia.ca>
@ 2013-11-27 21:54 ` Venky Kandaswamy <venky@adchemy.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Venky Kandaswamy @ 2013-11-27 21:54 UTC (permalink / raw)
  To: pgsql-sql; emilu@encs.concordia.ca <emilu@encs.concordia.ca>

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@postgresql.org <pgsql-sql-owner@postgresql.org> on behalf of Emi Lu <emilu@encs.concordia.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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


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



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


end of thread, other threads:[~2013-11-27 21:54 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-11-27 21:46 isnumeric(varchar) by psql Emi Lu <emilu@encs.concordia.ca>
2013-11-27 21:54 ` Venky Kandaswamy <venky@adchemy.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox