Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 3F306476283 for ; Tue, 14 May 2002 18:02:07 -0400 (EDT) Received: from ciderbox.stanaway.net (ciderbox.stanaway.net [170.76.50.98]) by postgresql.org (Postfix) with ESMTP id 7612147657C for ; Tue, 14 May 2002 17:47:39 -0400 (EDT) Received: by ciderbox.stanaway.net (Postfix, from userid 1000) id 0973793659; Tue, 14 May 2002 16:47:39 -0500 (CDT) Subject: Re: can't cast varchar as integer? From: David Stanaway To: Scott Royston Cc: pgsql-sql@postgresql.org In-Reply-To: <4EE21904-676C-11D6-BF4D-000393577144@mac.com> References: <4EE21904-676C-11D6-BF4D-000393577144@mac.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-Djt8smiN45Ra8NihkgSF" X-Mailer: Ximian Evolution 1.0.3 Date: 14 May 2002 16:47:39 -0500 Message-Id: <1021412859.992.2468.camel@ciderbox> Mime-Version: 1.0 X-Archive-Number: 200205/143 X-Sequence-Number: 7779 --=-Djt8smiN45Ra8NihkgSF Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Tue, 2002-05-14 at 13:56, Scott Royston wrote: > Mac OSX, postgresql 7.2.1 >=20 > what's the reasoning behind not being able to cast a varchar as=20 > integer? this seems very weird to me: >=20 > LEDEV=3D# create table test (foo varchar(5), bar text); > LEDEV=3D# insert into test (foo, bar) values ('123', '123'); > LEDEV=3D# select cast(foo as integer) from test; > ERROR: Cannot cast type 'character varying' to 'integer' > LEDEV=3D# select cast(bar as integer) from test; > bar > ----- > 123 > (1 row) Try this:=20 scratch=3D# select foo::text::integer from test; foo=20 ----- 123 (1 row) Or:=20 scratch=3D# select int4(foo) from test; int4=20 ------ 123 (1 row) -- David Stanaway --=-Djt8smiN45Ra8NihkgSF Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iQEXAwUAPOGF+76yIDFGeSAyFALpnQP+Jkk/FofTj0KoC4Yj9RnA9fj4qpN/DOPL Q7kqSWj58JOyo8wDfWQb2ydZ3+ygisTG9bkfGyyYASO1fsJyzsD+XW8Cuw8efa22 z4Huuw8vcPx1BCrDYN1lwUUsM5+48aYln7vrDZ4f/5jC9HetsOSks5QPuhwy66H5 KnQfRZ38i5wEAIt/mkwhdgllPVp1VJpyvvNp/3WeofnBMJZpb5m3Cr7lnxIl7hcw 16afBuqDcwg5WLbdNX7fx6JO3nLxCamzwKnrtfRFZZ4mZRWhvZIL2tU1qEuXZC5A +1gUAc+A49VH1wnJH9vbNpC9X3Pdn7nJudR/lsdOdOO83Ul4ut8OucWY =9rms -----END PGP SIGNATURE----- --=-Djt8smiN45Ra8NihkgSF--