Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 14B5B475C1D for ; Tue, 9 Apr 2002 13:48:19 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 9BF27D60C; Tue, 9 Apr 2002 10:48:10 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 30BB55C01; Tue, 9 Apr 2002 10:48:10 -0700 (PDT) Date: Tue, 9 Apr 2002 10:48:09 -0700 (PDT) From: Stephan Szabo To: Peter Atkins Cc: "'pgsql-sql@postgresql.org'" Subject: Re: type conversion? In-Reply-To: <02E689F991FFD311A75D009027B6A73E0886EAC7@corp_mail01.sf.nextcard.com> Message-ID: <20020409104600.H95735-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200204/104 X-Sequence-Number: 7369 On Tue, 9 Apr 2002, Peter Atkins wrote: > I have a column "total_hours | character varying(5) " and I am unable to > perform the aggrigate function SUM() because of the column type. > Without changing the type is there a way to convert the datatype by using > CAST(), to_char() or something simular? So that I may calculate the SUM(). > > SELECT SUM(total_hours) AS hours FROM my_table WHERE flag='$flag'; I think this may work: SELECT SUM(to_number(total_hours, '99999')) from my_table where ...