| From: | Joe Conway <mail(at)joeconway(dot)com> |
|---|---|
| To: | George McQuade <josslad(at)yahoo(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Table conversion query... |
| Date: | 2003-08-20 20:19:53 |
| Message-ID: | 3F43D7E9.2000804@joeconway.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2003-08-20 20:32:19 | Re: "SELECT IN" Still Broken in 7.4b |
| Previous Message | Tom Lane | 2003-08-20 20:12:27 | Re: Before/After Trigger User Switching |