pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: greg@turnstep.com
To: pgsql-sql@postgresql.org
Subject: Re: conversi ms-sql7 vs postgresql 7.3
Date: Mon, 10 Feb 2003 13:40:54 -0800
Message-ID: <200302101340.54373.josh@agliodbs.com> (raw)
In-Reply-To: <8632f12da1f37b38ed7a9264c07c5bdb@biglumber.com>
References: <8632f12da1f37b38ed7a9264c07c5bdb@biglumber.com>

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




view thread (6+ messages)

Message-ID: <200302101340.54373.josh@agliodbs.com>
Permalink:  ../200302101340.54373.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200302101340.54373.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, greg@turnstep.com
  Subject: Re: conversi ms-sql7 vs postgresql 7.3
  In-Reply-To: <200302101340.54373.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox