Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8995E476420 for ; Fri, 24 Jan 2003 14:43:28 -0500 (EST) Received: from brasileiro.net (slxwy.dorms.usu.edu [129.123.227.56]) by postgresql.org (Postfix) with ESMTP id A0E654762B8 for ; Fri, 24 Jan 2003 14:06:52 -0500 (EST) Received: from roberto by brasileiro.net with local (Exim 3.35 #1 (Debian)) id 18c97M-0005PX-00; Fri, 24 Jan 2003 12:03:56 -0700 Date: Fri, 24 Jan 2003 12:03:56 -0700 From: Roberto Mello To: Tom Lane Cc: daq , Luke Pascoe , pgsql-sql@postgresql.org Subject: Re: CAST from VARCHAR to INT Message-ID: <20030124190356.GC20178@cc.usu.edu> References: <01df01c2c354$2bac5a60$3200000a@K2> <21242862808.20030124112835@ugyvitelszolgaltato.hu> <13400.1043422949@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <13400.1043422949@sss.pgh.pa.us> User-Agent: Mutt/1.4i X-message-flag: Please consider using an e-mail program other than Outlook. It's insecure. X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/403 X-Sequence-Number: 11268 On Fri, Jan 24, 2003 at 10:42:29AM -0500, Tom Lane wrote: > daq writes: > > Make your life easier! :) You must write a function like > > this: > > > create function "int4"(character varying) returns int4 as ' > > DECLARE > > input alias for $1; > > BEGIN > > return (input::text::int4); > > END; > > ' language 'plpgsql'; > > > When you try the cast varchar_field::integer or varchar_field::int4 Postgres call > > the function named int4 and takes varchar type parameter. > > Note that as of 7.3 you need to issue a CREATE CAST command; the name of > the function is not what drives this anymore. (Though following the old > naming convention that function name == return type still seems like a > good idea.) Wow, I didn't even know of either of these features. Sounds useful. -Roberto -- +----| Roberto Mello - http://www.brasileiro.net/ |------+ + Computer Science Graduate Student, Utah State University + + USU Free Software & GNU/Linux Club - http://fslc.usu.edu/ + Friends encourage friends to use Win(e)dows - under Linux!