X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id B9A5BD1B9A6 for ; Wed, 20 Aug 2003 17:26:46 -0300 (ADT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 86452-10 for ; Wed, 20 Aug 2003 17:26:37 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id 17A5FD1BB4C for ; Wed, 20 Aug 2003 17:26:35 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 35671; Wed, 20 Aug 2003 12:43:57 -0700 Message-ID: <3F43D7E9.2000804@joeconway.com> Date: Wed, 20 Aug 2003 13:19:53 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: George McQuade Cc: pgsql-sql@postgresql.org Subject: Re: Table conversion query... References: <20030820193143.23054.qmail@web41611.mail.yahoo.com> In-Reply-To: <20030820193143.23054.qmail@web41611.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/241 X-Sequence-Number: 14857 George McQuade wrote: > date tran gl amt > 08/20/03 1001 3010 -30.00 > 08/20/03 1001 1030 -300.00 > 08/20/03 1001 1060 +330.00 > 08/20/03 1002 ...next transaction > ... > and I need to convert to: > > date glcr gldb amt > 08/20/03 1060 3010 30.00 > 08/20/03 1060 1030 300.00 > > in other words, the negative gl's go into gldb > and they make up the total for the positive gl. > > is there a way to accomplish this in postgresql? > or should I implement it inside the java app? There's no simple way to do this in Postgres. You could do it with a PL/pgSQL table function, or for better performance a C function. There are a couple of questions yet to be answered though: 1) Can there ever be more than one credit account, e.g. -30, -300, +150, +180? 2) What happens if sum(neg values) != sum(pos values)? Throw an error? Joe