Re: conversi ms-sql7 vs postgresql 7.3

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: greg(at)turnstep(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: conversi ms-sql7 vs postgresql 7.3
Date: 2003-02-10 21:40:54
Message-ID: 200302101340.54373.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Greg,

> > command in ms-sql 7 can use calculate field (column) balance from id=1
> > to id=4: "update xx set bal=balance=bal+debet-credit"
>
> You cannot do such a thing in SQL alone: you must use a procedural
> language. One way is with plpgsql:

You're mistaken, I think (I can't find the original e-mail in this thread)

UPDATE totals SET balance = total_bal
FROM (SELECT acct_id, (sum(credit) - sum(debit)) as total_bal
FROM accounts GROUP BY acct_id) tb
WHERE tb.acct_id = totals.acct_id
AND totals.acct_id = $selection

... would update a ficticious "totals" table with the sum of credits and
debits for a particular account.
--
-Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Eduardo 2003-02-10 23:53:13 PL/PGSQL TUTORIAL
Previous Message greg 2003-02-10 21:04:24 Re: conversi ms-sql7 vs postgresql 7.3