Help on update.

From: paulo matadr <saddoness(at)yahoo(dot)com(dot)br>
To: GENERAL <pgsql-general(at)postgresql(dot)org>
Subject: Help on update.
Date: 2010-05-26 13:46:00
Message-ID: 143637.77662.qm@web52506.mail.re2.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

create table test(i number , j number);

insert into test values(1,2)
insert into test values(1,3)
insert into test values(1,4)

select * from test;
I J
---------- ----------
1 2
1 3
1 4

My intentions:
after update
select * from test;
I J
---------- ----------
1 2
1 3+2
1 4+3
after
select * from test;
I J
---------- ----------
1 2
1 5+2
1 7+5

In oracle,I use this:
update test x
set x.j = x.j + (select lag_j
from (select i, j, nvl(lag(j) over (order by i,j) ,0) as lag_j
from test) y
where x.i = y.i and x.j = y.j)

how can translate this for work in postgres?

Thanks's

Paul

Paulo

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-05-26 14:04:59 Re: recovery after interrupt in the middle of a previous recovery
Previous Message Kenichiro Tanaka 2010-05-26 11:37:45 Re: effective_io_concurrency details