Re: Conversion of string to int using digits at beginning

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Conversion of string to int using digits at beginning
Date: 2008-11-18 17:51:08
Message-ID: 4923008C.6060602@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 18/11/2008 17:33, Andrus wrote:

> create temp table test (test char(20));
> insert into test values ('12');
> insert into test values ('23/3');
> insert into test values ('AX/3');
> select max(test::int) from test;
>
> but got
>
> ERROR: invalid input syntax for integer: "23/3 "
>
> How to fix this so that this query returns 23 without error ?

It's not a question of "fixing" - it's not broken! :-)

You could use a regular expression in substring() to get just the
numeric bits.

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sam Mason 2008-11-18 17:55:44 Re: Conversion of string to int using digits at beginning
Previous Message Simon Connah 2008-11-18 17:50:33 Re: No serial type