Conversion of string to int using digits at beginning - Mailing list pgsql-general

From Andrus
Subject Conversion of string to int using digits at beginning
Date
Msg-id gfuua6$u21$1@news.hub.org
Whole thread Raw
Responses Re: Conversion of string to int using digits at beginning  (Raymond O'Donnell <rod@iol.ie>)
Re: Conversion of string to int using digits at beginning  (Sam Mason <sam@samason.me.uk>)
List pgsql-general
Table contains CHAR(20) type columns containing numbers and other values.

I need to obtain max integer considering only numbers from start of column
up to first non-integer character.

I tried

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 ?

Andrus.


pgsql-general by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: No serial type
Next
From: Raymond O'Donnell
Date:
Subject: Re: No serial type