Received: from bologna.nettuno.it (bologna.nettuno.it [193.43.2.1]) by hub.org (8.9.3/8.9.1) with ESMTP id JAA59764 for ; Thu, 22 Apr 1999 09:55:31 -0400 (EDT) (envelope-from jose@sferacarta.com) Received: from proxy.sferacarta.com (mail@sfcabop1.nettuno.it [193.207.10.213]) by bologna.nettuno.it (8.8.6/8.8.6/NETTuno 3.1) with ESMTP id PAA16839; Thu, 22 Apr 1999 15:55:11 +0200 (MDT) Received: from rosso.sferacarta.com (sferacarta.com) [10.20.30.5] by proxy.sferacarta.com with esmtp (Exim 2.05 #1 (Debian)) id 10aKPg-0000oU-00; Thu, 22 Apr 1999 14:25:12 +0000 Message-ID: <371F1510.F86C876B@sferacarta.com> Date: Thu, 22 Apr 1999 14:24:48 +0200 From: =?iso-8859-1?Q?Jos=E9?= Soares X-Mailer: Mozilla 4.5 [it] (Win95; I) X-Accept-Language: it MIME-Version: 1.0 To: JT Kirkpatrick CC: "'pgsql-sql@hub.org'" Subject: Re: [SQL] convert text to number or number to text References: <01BE8C04.0A52A9E0.jt-kirkpatrick@mpsllc.com> Content-Type: multipart/alternative; boundary="------------479704927F8AFBF9593B9C90" --------------479704927F8AFBF9593B9C90 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit JT Kirkpatrick ha scritto: > I'm trying to do an update query that compares an int4 field to a variable > which I think contains a string (it was passed in through cgi.pm). can I > convert that string to an integer? - it will always be a number passing > through. I vaguely remember oracle having a to_number function - does > postgres have something similar? > > jt Try this: prova=> create table test(t text, i integer); CREATE prova=> insert into test values('123',123); INSERT 64579 1 prova=> select cast(i as text),cast(t as int)from test; text|int4 ----+---- 123| 123 (1 row) José --------------479704927F8AFBF9593B9C90 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit JT Kirkpatrick ha scritto:
I'm trying to do an update query that compares an int4 field to a variable
which I think contains a string (it was passed in through cgi.pm).  can I
convert that string to an integer? - it will always be a number passing
through.  I vaguely remember oracle having a to_number function - does
postgres have something similar?

jt

Try this:

prova=> create table test(t text, i integer);
CREATE

prova=> insert into test values('123',123);
INSERT 64579 1

prova=> select cast(i as text),cast(t as int)from test;
text|int4
----+----
 123| 123
(1 row)

José
  --------------479704927F8AFBF9593B9C90--