SQL state: 22P02
SQL state: 22P02
От:
Franklin Haut <franklin.haut@gmail.com>
Дата:
Hi,
I got the message "SQL state: 22P02"
to produce:
create table test (num varchar(20));
insert into test (num) values (null);
select * from test where cast(num as int8) = 0; --ok, no error
insert into test (num) values ('123123');
select * from test where cast(num as int8) = 123123; --ok, no error
insert into test (num) values (' ');
select * from test where cast(num as int8) = 123123; -- error
select * from test where case when trim(num) <> '' then cast(num as int8) = 123123 else false end; -- ok, changed query and no error
insert into test (num) values ('a');
select * from test where cast(num as int8) = 123123; -- error
select * from test where case when trim(num) <> '' then cast(num as int8) = 123123 else false end; -- error
I need get all tuples was the table have converting the characters to number. If one conversion fail there not displayed.
Ex:
num return
---- ------
0 0
null false
12 12
a false
12ab false
it´s possible get these results ?
other question:
Why this message ("SQL state: 22P02") is not displayed with the SQL command on log in data/pg_log ?
only appears
2007-11-22 12:55:13 BRT ERROR: invalid input syntax for integer: "a"
thanks,
Franklin Haut
Re: SQL state: 22P02
От:
"Rodrigo De León" <rdeleonp@gmail.com>
Дата:
On Nov 22, 2007 11:24 AM, Franklin Haut wrote:
> num return
> ---- ------
> 0 0
> null false
> 12 12
> a false
> 12ab false
>
> it´s possible get these results ?
Try:
SELECT NUM , CASE WHEN TRIM(NUM) ~ '^[0-9]+(.[0-9]+){0,1}$' THEN NUM ELSE 'false' END AS RETURN
FROM TEST;