X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 403B59FA886 for ; Fri, 5 May 2006 18:58:11 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 22610-03 for ; Fri, 5 May 2006 18:58:06 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from zixvpm01.seton.org (zixvpm01.seton.org [207.193.126.161]) by postgresql.org (Postfix) with ESMTP id 856A29FA3A3 for ; Fri, 5 May 2006 18:58:06 -0300 (ADT) Received: from zixvpm01.seton.org (ZixVPM [127.0.0.1]) by Outbound.seton.org (Proprietary) with ESMTP id 92E9DA7D35 for ; Fri, 5 May 2006 16:58:05 -0500 (CDT) Received: from mx2-out.seton.org (unknown [10.21.254.241]) by zixvpm01.seton.org (Proprietary) with ESMTP id 2CAA0A7CE4; Fri, 5 May 2006 16:58:05 -0500 (CDT) Received: from localhost (unknown [127.0.0.1]) by mx2-out.seton.org (Postfix) with ESMTP id 1F8CB1786; Fri, 5 May 2006 16:58:05 -0500 (CDT) Received: from mx2-out.seton.org ([10.21.254.241]) by localhost (mx2 [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 09146-25; Fri, 5 May 2006 16:58:05 -0500 (CDT) Received: from ausexfe01.seton.org (ausexfe01.seton.org [10.20.10.211]) by mx2-out.seton.org (Postfix) with ESMTP id 1011C1772; Fri, 5 May 2006 16:58:05 -0500 (CDT) Received: from AUSEX3VS1.seton.org ([10.20.10.114]) by ausexfe01.seton.org with Microsoft SMTPSVC(6.0.3790.211); Fri, 5 May 2006 16:58:04 -0500 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: Returning String as Integer Date: Fri, 5 May 2006 16:58:03 -0500 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] Returning String as Integer Thread-Index: AcZwjl98V8TDKNq1Q2uVfruJ4kcCzAAADbog From: "Hogan, James F. Jr." To: "Jorge Godoy" Cc: X-OriginalArrivalTime: 05 May 2006 21:58:04.0943 (UTC) FILETIME=[FC6EE1F0:01C6708E] X-Virus-Scanned: by amavisd-new at seton.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/61 X-Sequence-Number: 25092 Here is a Perl function a friend of mine wrote to help with this... Problems I ran into were errors because of NON NUMERIC Characters in the String... Casting would fail It doesn't catch all cases but it has been quite helpful to me $x =3D $_[0]; $x =3D~ s/^[^-\d\.]*//; $x =3D~ s/\,//g; $x =3D $x * 1; return $x; -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Jorge Godoy Sent: Friday, May 05, 2006 4:52 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Returning String as Integer Em Sexta 05 Maio 2006 18:37, Kashmira Patel (kupatel) escreveu: > Hi all, > I have a table with a column of type 'text'. It mainly contains > numbers. Is there any way to select a value from this column and return > it as an integer? testing=3D# select '123'::integer; int4=20 ------ 123 (1 registro) testing=3D#=20 --=20 Jorge Godoy ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend