pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Viorel Dragomir <bc@vio.ro>
To: Greg Stark <gsstark@mit.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: summing tables
Date: Tue, 15 Jul 2003 18:06:42 +0300
Message-ID: <010201c34ae2$b35b3830$0600a8c0@fix.ro> (raw)
References: <20030715140921.7c5a6a6c.erik@thiele-hydraulik.de>
	<001501c34aca$e70ca280$0600a8c0@fix.ro>
	<20030715143925.54716ed4.erik@thiele-hydraulik.de>
	<007101c34ad6$3e0249e0$0600a8c0@fix.ro>
	<878yqzn8k5.fsf@stark.dyndns.tv>

The primary problem was that the update command doesn't modify rows in the
order u want to do it.
I think the update starts with the latest inserted rows. I guess.

Anyway, in real life this update modifies only one row with a value wich is
diff of null.
It was really handy if it was specified the option ORDER for the update
command.

----- Original Message -----
From: "Greg Stark" <gsstark@mit.edu>
To: "Viorel Dragomir" <bigchief@vio.ro>
Cc: <pgsql-sql@postgresql.org>
Sent: Tuesday, July 15, 2003 5:55 PM
Subject: Re: [SQL] summing tables


>
> To solve this problem efficiently you probably need the lead/lag analytic
> functions. Unfortunately Postgres doesn't have them.
>
> You could do it with something like:
>
> update foo set c = a+b+(select c from foo as x where seq < foo.seq ORDER
BY seq desc LIMIT 1)
>
> or the more standard but likely to be way slower:
>
> update foo set c = a+b+(select c from foo as x where seq = (select
max(seq) from foo as y where seq < foo.seq))
>
>
> However, i would suggest that if you have an implicit relationship between
> records you should make that relationship explicit with a foreign key. If
you
> had a column that contained the seq of the parent record then this would
be
> easy. I'm really puzzled how this query as currently specified could be
> useful.
>
>
> --
> greg
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster




view thread (13+ messages)  latest in thread

Message-ID: <010201c34ae2$b35b3830$0600a8c0@fix.ro>
Permalink:  ../010201c34ae2$b35b3830$0600a8c0@fix.ro/
Also on:    postgresql.org/message-id/010201c34ae2$b35b3830$0600a8c0@fix.ro

 · 

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: bc@vio.ro, gsstark@mit.edu
  Subject: Re: summing tables
  In-Reply-To: <010201c34ae2$b35b3830$0600a8c0@fix.ro>

* 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