Update Current Row Based on Prior Row

From: Philip Brooks <philswatch(at)yahoo(dot)com>
To: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Update Current Row Based on Prior Row
Date: 2012-06-02 16:43:43
Message-ID: 1338655423.91460.YahooMailNeo@web121403.mail.ne1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I had what I thought was a simple update query.. and it has stumped me.
I have a table ordered by a SERIAL named ROWID.
In that table I have a column named TITLE.
Where TITLE is null, I want to set it equal to the previous row's TITLE.

In SQLite, I did it with this:
UPDATE bf
SET title = (
  SELECT title
  FROM bf AS prev
  WHERE title IS NOT NULL AND prev.rowid < bf.rowid
  ORDER BY prev.rowid DESC
  LIMIT 1
)
WHERE title IS NULL

The update is not porting to Postgresql.

Ideas?

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2012-06-02 21:17:11 Re: Update Current Row Based on Prior Row
Previous Message Tom Lane 2012-06-01 19:05:49 Re: database in different location owned by different user