In 7.4, how do I declare that a column in a table is to be
automatically set to the value of some fixed expression whenever a row
is updated?
Eg column last_modified is always set to current_timestamp
Chris
--
Chris Velevitch
Manager - Adobe Platform Users Group, Sydney
m: 0415 469 095
Hello,
2008/9/11 Chris Velevitch [EMAIL PROTECTED]:
In 7.4, how do I declare that a column in a table is to be
automatically set to the value of some fixed expression whenever a row
is updated?
Eg column last_modified is always set to current_timestamp
you should to use trigger
regards
On Thu, Sep 11, 2008 at 6:01 PM, Pavel Stehule [EMAIL PROTECTED] wrote:
you should to use trigger
I've never used trigger before, it looks messy and error prone having
to write functions.
How is it that you can declare the default value of a column on insert
but not on update?
Chris
--
Chris
On Thu, Sep 11, 2008 at 1:35 AM, Chris Velevitch
[EMAIL PROTECTED] wrote:
In 7.4, how do I declare that a column in a table is to be
automatically set to the value of some fixed expression whenever a row
is updated?
Eg column last_modified is always set to current_timestamp
A trigger as
On Thu, Sep 11, 2008 at 1:35 AM, Chris Velevitch
[EMAIL PROTECTED] wrote:
In 7.4, how do I declare that a column in a table is to be
automatically set to the value of some fixed expression whenever a row
is updated?
Oh yeah, if you can upgrade from 7.4 that would be a good idea, it's
getting a
How is it that you can declare the default value of a column on insert
but not on update?
You can do this without triggers (at least on 8.3).
UPDATE foo
SET field1 = 2,
field2 = default
WHERE field3 = 22
I just tested it and it will set the value back to the default. The
caveat here is
On Fri, Sep 12, 2008 at 12:50 PM, Artacus [EMAIL PROTECTED] wrote:
You can do this without triggers (at least on 8.3).
UPDATE foo
SET field1 = 2,
field2 = default
WHERE field3 = 22
That means I have to then go through all my code and make sure I set
the fields value. If I forget to
On Fri, Sep 12, 2008 at 1:53 AM, Scott Marlowe [EMAIL PROTECTED] wrote:
Here's a simple example of last modified trigger using plpgsql from way back:
-- FUNCTION --
CREATE FUNCTION modtime () RETURNS opaque AS '
BEGIN
new.lm :=''now'';
RETURN new;
END;
' LANGUAGE
On Thu, Sep 11, 2008 at 9:10 PM, Chris Velevitch
[EMAIL PROTECTED] wrote:
On Fri, Sep 12, 2008 at 1:53 AM, Scott Marlowe [EMAIL PROTECTED] wrote:
Here's a simple example of last modified trigger using plpgsql from way back:
-- FUNCTION --
CREATE FUNCTION modtime () RETURNS opaque AS '
On Thu, Sep 11, 2008 at 8:50 PM, Artacus [EMAIL PROTECTED] wrote:
How is it that you can declare the default value of a column on insert
but not on update?
You can do this without triggers (at least on 8.3).
UPDATE foo
SET field1 = 2,
field2 = default
WHERE field3 = 22
I just tested
That means I have to then go through all my code and make sure I set
the fields value. If I forget to modify one statement, things will
break.
Right, that's why the right answer for what you want to do is to have a
trigger. I was just giving you an alternative since you didn't like the
11 matches
Mail list logo