Re: [GENERAL] declare column update expression

2008-09-11 Thread Artacus
> 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 tr

Re: [GENERAL] declare column update expression

2008-09-11 Thread Scott Marlowe
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 >

Re: [GENERAL] declare column update expression

2008-09-11 Thread Scott Marlowe
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 opaq

Re: [GENERAL] declare column update expression

2008-09-11 Thread Chris Velevitch
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; > ' LA

Re: [GENERAL] declare column update expression

2008-09-11 Thread Chris Velevitch
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 t

Re: [GENERAL] declare column update expression

2008-09-11 Thread Artacus
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

Re: [GENERAL] declare column update expression

2008-09-11 Thread Scott Marlowe
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 getti

Re: [GENERAL] declare column update expression

2008-09-11 Thread Scott Marlowe
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 a

Re: [GENERAL] declare column update expression

2008-09-11 Thread Chris Velevitch
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 -- Chri

Re: [GENERAL] declare column update expression

2008-09-11 Thread Pavel Stehule
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 reg

[GENERAL] declare column update expression

2008-09-11 Thread Chris Velevitch
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 www.apug