Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 97B1D4768BA for ; Fri, 24 Jan 2003 10:59:29 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 8ADF54772AA for ; Fri, 24 Jan 2003 10:42:28 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h0OFgT5u013401; Fri, 24 Jan 2003 10:42:29 -0500 (EST) To: daq Cc: "Luke Pascoe" , pgsql-sql@postgresql.org Subject: Re: CAST from VARCHAR to INT In-reply-to: <21242862808.20030124112835@ugyvitelszolgaltato.hu> References: <01df01c2c354$2bac5a60$3200000a@K2> <21242862808.20030124112835@ugyvitelszolgaltato.hu> Comments: In-reply-to daq message dated "Fri, 24 Jan 2003 11:28:35 +0100" Date: Fri, 24 Jan 2003 10:42:29 -0500 Message-ID: <13400.1043422949@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/398 X-Sequence-Number: 11263 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.) regards, tom lane