Re: Updating rows (automatically) that are selected

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Assad Jarrahian <jarraa(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Updating rows (automatically) that are selected
Date: 2006-01-24 09:45:16
Message-ID: 20060124094516.GA7766@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jan 18, 2006 at 14:26:28 -0700,
Assad Jarrahian <jarraa(at)gmail(dot)com> wrote:
> Hello,
> I have a table called X
> it contains 3 fields of importance(amongst others).
> time (timestamp), snooze (int) , inbox (int)
>
> The time column sometimes has null values.
> What I want is that every time a row is selected, if the time is a
> null value, it is set to now() and snooze is set to 0 and inbox to 1
>
> How would I go about doing this. I looked into Creating Rules, but I
> am not sure if this will work.

Are you talking about updating the underlying roles or just returning
modified information?

I don't think this is going to be easy to do in the case where you update
the underlying rows. Normally you update data like that using triggers
rather than rules, but you can't trigger on selects.

Maybe you should be changing the data when you store it, rather than the
first time you read it back?

If you don't want to update the underlying data, then using a view with a
CASE statement is probably the easiest soltuion.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2006-01-24 09:57:44 Re: Surrogate keys (Was: enums)
Previous Message R, Rajesh (STSD) 2006-01-24 09:40:18 Re: [HACKERS] [PATCH] Better way to check for getaddrinfo function.