From jt-kirkpatrick@mpsllc.com Wed Apr 21 18:31:57 1999 Received: from s20.highertech.net (root@s20.highertech.net [209.54.120.20]) by hub.org (8.9.3/8.9.1) with ESMTP id OAA11361 for ; Wed, 21 Apr 1999 14:31:57 -0400 (EDT) (envelope-from jt-kirkpatrick@mpsllc.com) Received: from kirkpatrickjt (whiteoak-34.highertech.net [209.140.56.34] (may be forged)) by s20.highertech.net (8.8.6/8.8.6) with SMTP id NAA04774 for ; Wed, 21 Apr 1999 13:47:09 -0400 Received: by localhost with Microsoft MAPI; Wed, 21 Apr 1999 14:34:19 -0400 Message-ID: <01BE8C04.0A52A9E0.jt-kirkpatrick@mpsllc.com> From: JT Kirkpatrick To: "'pgsql-sql@hub.org'" Subject: convert text to number or number to text Date: Wed, 21 Apr 1999 14:34:18 -0400 Organization: MPS, LLC X-Mailer: Microsoft Internet E-mail/MAPI - 8.0.0.4211 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 From jose@sferacarta.com Thu Apr 22 13:55:31 1999 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-- From jose@sferacarta.com Thu Apr 22 13:55:34 1999 Received: from bologna.nettuno.it (bologna.nettuno.it [193.43.2.1]) by hub.org (8.9.3/8.9.1) with ESMTP id JAA59775 for ; Thu, 22 Apr 1999 09:55:34 -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 PAA24823; Thu, 22 Apr 1999 15:55:10 +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 10aKUf-0000oe-00; Thu, 22 Apr 1999 14:30:21 +0000 Message-ID: <371F1644.2B73C65C@sferacarta.com> Date: Thu, 22 Apr 1999 14:29:56 +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: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit This should work: select cast('123' as int), cast(123 as text); José 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