Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vln48-0008TP-2g for pgsql-sql@arkaria.postgresql.org; Wed, 27 Nov 2013 21:54:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vln47-0001lo-Iz for pgsql-sql@arkaria.postgresql.org; Wed, 27 Nov 2013 21:54:35 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vln46-0001li-QN for pgsql-sql@postgresql.org; Wed, 27 Nov 2013 21:54:34 +0000 Received: from mail-by2lp0241.outbound.protection.outlook.com ([207.46.163.241] helo=na01-by2-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vln3y-0003bD-Tm for pgsql-sql@postgresql.org; Wed, 27 Nov 2013 21:54:33 +0000 Received: from BY2PR05MB237.namprd05.prod.outlook.com (10.242.41.146) by BY2PR05MB239.namprd05.prod.outlook.com (10.242.41.143) with Microsoft SMTP Server (TLS) id 15.0.820.5; Wed, 27 Nov 2013 21:54:23 +0000 Received: from BY2PR05MB237.namprd05.prod.outlook.com ([169.254.15.61]) by BY2PR05MB237.namprd05.prod.outlook.com ([169.254.15.174]) with mapi id 15.00.0820.005; Wed, 27 Nov 2013 21:54:22 +0000 From: Venky Kandaswamy To: pgsql-sql , "emilu@encs.concordia.ca" Subject: Re: isnumeric(varchar) by psql Thread-Topic: [SQL] isnumeric(varchar) by psql Thread-Index: AQHO67pGTzV1laxzhUWy5ZnjUSoiXpo5nkrh Date: Wed, 27 Nov 2013 21:54:22 +0000 Message-ID: References: <52966824.8070404@encs.concordia.ca> In-Reply-To: <52966824.8070404@encs.concordia.ca> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [70.42.188.254] x-forefront-prvs: 004395A01C x-forefront-antispam-report: SFV:NSPM; SFS:(377454003)(199002)(189002)(74316001)(80976001)(47976001)(77982001)(47736001)(65816001)(59766001)(80022001)(50986001)(4396001)(33646001)(81816001)(63696002)(54316002)(49866001)(31966008)(56776001)(79102001)(15202345003)(19580405001)(15975445006)(74662001)(19580395003)(74366001)(83322001)(81686001)(2656002)(81542001)(74876001)(46102001)(87266001)(53806001)(77096001)(56816003)(76482001)(76796001)(76786001)(83072001)(81342001)(47446002)(74502001)(54356001)(69226001)(85306002)(74706001)(76576001)(51856001)(87936001)(66066001)(24736002); DIR:OUT; SFP:; SCL:1; SRVR:BY2PR05MB239; H:BY2PR05MB237.namprd05.prod.outlook.com; CLIP:70.42.188.254; FPR:; RD:InfoNoRecords; A:1; MX:1; LANG:en; Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: adchemy.com X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Depends on what you want to really do. You can simply cast the field to num= eric ( col::numeric) and it will convert it - or fail if it cannot.=20 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= .=20 ________________________________________ Venky Kandaswamy Principal Engineer, Adchemy Inc. 925-200-7124 ________________________________________ From: pgsql-sql-owner@postgresql.org on be= half of Emi Lu 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 --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql