X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 604EE5E46CD for ; Tue, 17 Aug 2004 10:49:09 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73899-08 for ; Tue, 17 Aug 2004 13:49:02 +0000 (GMT) Received: from ws.spps.com.br (ws.spps.com.br [200.248.176.2]) by svr1.postgresql.org (Postfix) with ESMTP id 4CFC05E46F1 for ; Tue, 17 Aug 2004 10:48:56 -0300 (ADT) Received: from [127.0.0.1] (200-203-055-075.nhoce7002.e.brasiltelecom.net.br [200.203.55.75]) (authenticated) by ws.spps.com.br (8.11.6p2/8.12.6) with ESMTP id i7HDmqb05501 for ; Tue, 17 Aug 2004 10:48:52 -0300 Message-ID: <41220CC1.1050608@nho.com.br> Date: Tue, 17 Aug 2004 10:48:49 -0300 From: =?ISO-8859-1?Q?Elieser_Le=E3o?= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040616 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Verifying data type Content-Type: multipart/alternative; boundary="------------020907070702010305060405" X-SPPS-MailScanner-Information: Contate a SPPS para maiores informacoes. +55 (51) 582-3666 X-SPPS-MailScanner: Found to be clean X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.0 tagged_above=0.0 required=5.0 tests=HTML_20_30, HTML_MESSAGE, HTML_TITLE_EMPTY X-Spam-Level: * X-Archive-Number: 200408/163 X-Sequence-Number: 18660 This is a multi-part message in MIME format. --------------020907070702010305060405 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Thanks, but the number may be a float, like '1.23,00', '12.323,00', '12,34'.... :( The regex works fine if it just an integer... Have some regex to "compare"? Tom Lane wrote: >=?ISO-8859-1?Q?Elieser_Le=E3o?= 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 > > > --------------020907070702010305060405 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Thanks, but the number may be a float, like '1.23,00', '12.323,00', '12,34'.... :(
The regex works fine if it just an integer...

Have some regex to "compare"?

Tom Lane wrote:
=?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

  

--------------020907070702010305060405--