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 E57F0D1BB9B for ; Wed, 20 Aug 2003 18:29:05 -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 10769-03 for ; Wed, 20 Aug 2003 18:28:55 -0300 (ADT) Received: from web41605.mail.yahoo.com (web41605.mail.yahoo.com [66.218.93.105]) by svr1.postgresql.org (Postfix) with SMTP id 5954BD1B8E0 for ; Wed, 20 Aug 2003 18:28:52 -0300 (ADT) Message-ID: <20030820212854.13264.qmail@web41605.mail.yahoo.com> Received: from [66.139.64.60] by web41605.mail.yahoo.com via HTTP; Wed, 20 Aug 2003 14:28:54 PDT Date: Wed, 20 Aug 2003 14:28:54 -0700 (PDT) From: George McQuade Subject: Re: Table conversion query... To: Joe Conway Cc: pgsql-sql@postgresql.org In-Reply-To: <3F43D7E9.2000804@joeconway.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/255 X-Sequence-Number: 14871 --- Joe Conway wrote: > 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. Interesting, my C is gone a long time ago. Would the table function be fairly complex for someone who's never done one? I'm tempted by the java option, but initial jdbc speed tests don't look very promising (the avg file has 1/2 million records). > 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? No, so far all the examples I've seen involve a single credit account. > 2) What happens if sum(neg values) != sum(pos > values)? Throw an error? Yes, this would indicate a system out of balance that requires external assistance. Thanks for the help. george __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com