pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: SQL state: 22P02
2+ messages / 2 participants
[nested] [flat]

* SQL state: 22P02
@ 2007-11-22 16:24 Franklin Haut <franklin.haut@gmail.com>
  2007-11-22 16:06 ` Re: SQL state: 22P02 Rodrigo De León <rdeleonp@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Franklin Haut @ 2007-11-22 16:24 UTC (permalink / raw)
  To: pgsql-sql

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<small><font face="Courier New">Hi,<br>
<br>
I got the message "SQL state: 22P02" <br>
<br>
<br>
<br>
<b>to produce:</b><br>
<br>
create table test (num varchar(20));<br>
<br>
insert into test (num) values (null);<br>
select * from test where cast(num as int8) = 0;&nbsp;&nbsp; --ok, no error<br>
insert into test (num) values ('123123');<br>
select * from test where cast(num as int8) = 123123;&nbsp;&nbsp; --ok, no error<br>
<br>
insert into test (num) values ('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ');<br>
select * from test where cast(num as int8) = 123123;&nbsp; -- error<br>
select * from test where case when trim(num) &lt;&gt; '' then cast(num
as int8) = 123123 else false end; -- ok, changed query and no error<br>
<br>
insert into test (num) values ('a');<br>
select * from test where cast(num as int8) = 123123;&nbsp; -- error<br>
select * from test where case when trim(num) &lt;&gt; '' then cast(num
as int8) = 123123 else false end;&nbsp; -- error<br>
<br>
I need get all tuples was the table have converting the characters to
number. If one conversion fail there not displayed. <br>
<br>
<b>Ex:</b><br>
&nbsp; num&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return<br>
&nbsp; ----&nbsp;&nbsp;&nbsp;&nbsp; ------<br>
&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<br>
&nbsp; null &nbsp; &nbsp;&nbsp; false<br>
&nbsp; 12 &nbsp; &nbsp; &nbsp;&nbsp; 12<br>
&nbsp; a &nbsp; &nbsp; &nbsp; &nbsp; false<br>
&nbsp; 12ab&nbsp; &nbsp; &nbsp; false<br>
</font></small><font face="Courier New"><small><br>
it&acute;s possible get these results ?<br>
<br>
<br>
other question:<br>
<br>
Why this message ("</small></font><small><font face="Courier New">SQL
state: 22P02</font></small><font face="Courier New"><small>") is not
displayed with the SQL command on log in data/pg_log ?<br>
only appears&nbsp;&nbsp;&nbsp;&nbsp; <br>
<br>
2007-11-22 12:55:13 BRT ERROR:&nbsp; invalid input syntax for integer: "a"<br>
<br>
<br>
thanks,<br>
<br>
Franklin Haut<br>
<br>
<br>
<br>
<br>
<br>
</small></font>
</body>
</html>



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: SQL state: 22P02
  2007-11-22 16:24 SQL state: 22P02 Franklin Haut <franklin.haut@gmail.com>
@ 2007-11-22 16:06 ` Rodrigo De León <rdeleonp@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Rodrigo De León @ 2007-11-22 16:06 UTC (permalink / raw)
  To: Franklin Haut <franklin.haut@gmail.com>; +Cc: pgsql-sql

On Nov 22, 2007 11:24 AM, Franklin Haut <franklin.haut@gmail.com> 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;


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-11-22 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-11-22 16:24 SQL state: 22P02 Franklin Haut <franklin.haut@gmail.com>
2007-11-22 16:06 ` Rodrigo De León <rdeleonp@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox