pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Elieser Leão <elieser@nho.com.br>
Cc: pgsql-sql@postgresql.org
Subject: Re: Verifying data type
Date: Mon, 16 Aug 2004 19:30:55 -0400
Message-ID: <18604.1092699055@sss.pgh.pa.us> (raw)
In-Reply-To: <4121241C.6000300@nho.com.br>
References: <4121241C.6000300@nho.com.br>

=?ISO-8859-1?Q?Elieser_Le=E3o?= <elieser@nho.com.br> writes:
> I need to verify if the data in p_valor is just number or it is a string.
> What is the best way to do this?

In PG 8.0 you can just do it exactly the way your Oracle original does,
viz try to cram it into a numeric variable and catch the exception if
any.

In earlier versions, my thoughts would run to some kind of string
matching test using a regular expression.

The regexp method is probably significantly faster though, so maybe you
want to do it anyway, especially if you don't need the full generality
of possible floating-point formats.  You might get away with something
as simple as "p_valor ~ '^[0-9]+$'" if you only care about unsigned
integer inputs.

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <18604.1092699055@sss.pgh.pa.us>
Permalink:  ../18604.1092699055@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18604.1092699055@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, elieser@nho.com.br
  Subject: Re: Verifying data type
  In-Reply-To: <18604.1092699055@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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