From: | Craig Ringer <craig(at)postnewspapers(dot)com(dot)au> |
---|---|
To: | Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> |
Cc: | Thom Brown <thombrown(at)gmail(dot)com>, PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>, pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Re: Updating column on row update |
Date: | 2009-11-22 23:26:32 |
Message-ID: | 4B09C8A8.9050209@postnewspapers.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On 23/11/2009 4:15 AM, Scott Marlowe wrote:
> On Sun, Nov 22, 2009 at 12:50 PM, Thom Brown <thombrown(at)gmail(dot)com> wrote:
>> Hi,
>> This should be simple, but for some reason I'm not quite sure what the
>> solution is. I want to be able to update the value of a column for rows
>> that have been updated. More specifically, if a row is updated, I want it's
>> modified_date column to be populated with the current time stamp. I've
>> looked at triggers and rules, and it looks like I'd need to create a
>> function just to achieve this which seems incredibly clumsy and unnecessary.
>> Could someone enlighten me?
>
> Well, you DO have to create a function, but it's not all that clumsy
> really. Also it's quite flexible so you can do lots of complex stuff
> and hide it away in a trigger function.
I do think this comes up often enough that a built-in trigger "update
named column with result of expression on insert" trigger might be
desirable. Especially if implemented in C to avoid the need for PL/PgSQL
and to reduce the CPU cost a smidge.
Hmm. CC'iing -hackers; there was a discussion earlier on it being
desirable to have more "[EASY]" TODO items, and this might be a good one
for the job.
So might "CREATE LANGUAGE ... IF NOT EXISTS". Maybe even "CREATE ROLE
... IF NOT EXISTS" and "CREATE USER ... IF NOT EXISTS" - I know I'd find
them really handy.
--
Craig Ringer
From | Date | Subject | |
---|---|---|---|
Next Message | Thom Brown | 2009-11-22 23:40:12 | Re: Updating column on row update |
Previous Message | Martijn van Oosterhout | 2009-11-22 22:22:18 | Re: Planning problem: pushing conditions through GROUP BY |
From | Date | Subject | |
---|---|---|---|
Next Message | Thom Brown | 2009-11-22 23:40:12 | Re: Updating column on row update |
Previous Message | Andrew Dunstan | 2009-11-22 23:05:28 | Re: WIP: log query in auto-explain |