Hi,
I have a varchar column, and I need to
1) check the value in it is an integer
2) get the integer value (as integer)
The problem is I can't suppose the're only correct
values - ie there can be something like 'xssdkjsd',
'230kdd' or even an empty string etc.
I've been loo
Tomas,
>I've written two on my own (see the functions below),
>but maybe there's something faster?
Nope. 'cept I'd combine those two functions into a single function that
returns NULL if the value isn't an integer.
--
--Josh
Josh Berkus
Aglio Database Solutions
San Francisco
---
Using CASE to avoid '':
CREATE TABLE test (number TEXT);
INSERT INTO test VALUES('123');
INSERT INTO test VALUES('a123b');
INSERT INTO test VALUES('');
teste=> SELECT CASE number WHEN '' THEN NULL ELSE
to_number(number,'990') END AS
number FROM test;;
number
123
123
[EMAIL PROTECTED] <[EMAIL PROTECTED]> schrieb:
> Hi,
>
>I have a varchar column, and I need to
>
>1) check the value in it is an integer
>2) get the integer value (as integer)
>
>The problem is I can't suppose the're only correct
>values - ie there can be something like 'xss
At 05:30 AM 8/17/05, Kretschmer Andreas wrote:
[EMAIL PROTECTED] <[EMAIL PROTECTED]> schrieb:
> Hi,
>
>I have a varchar column, and I need to
>
>1) check the value in it is an integer
>2) get the integer value (as integer)
test=# update foo set n = substring(t , '[0-9]')::int;
I
am 17.08.2005, um 12:46:01 -0400 mailte Frank Bax folgendes:
> >>1) check the value in it is an integer
> >>2) get the integer value (as integer)
> >test=# update foo set n = substring(t , '[0-9]')::int;
>
>
> I think you meant:
> update foo set n = substring(t , '[0-9]+')::int;