pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
maintaining a field for every UPDATION.
2+ messages / 2 participants
[nested] [flat]

* maintaining a field for every UPDATION.
@ 2002-01-04 06:47  Bhuvan A <bhuvansql@yahoo.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Bhuvan A @ 2002-01-04 06:47 UTC (permalink / raw)
  To: pgsql-sql


Hello all,

My need is something like this..

Consider in my database i have around 200 tables. In all my tables i
would like to maintain below 2 mandatory fields.

create_time timestamp,
modify_time timestamp.

So, for every insertions i would like to maintain create_time and i
had it, by setting default value to now() to that column.

Well, now i would like to maintain modify_time for every updation. how
can i? Using common plpgsql function i cant even able to refer OID
even during UPDATION. The result is

ERROR:  record old has no field oid
		or
ERROR:  record new has no field oid

One way: i can have seperate plpgsql function for every table and
apply conditions accordingly. But i dont think thats the consistent
way.

how else can i maintain modify_time field ?

Thankx in advance.

======================================================================
 Of course you have a purpose -- to find a purpose.
======================================================================

Regards,
Bhuvaneswar.




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: maintaining a field for every UPDATION.
@ 2002-01-04 08:19  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Bhuvan A <bhuvansql@yahoo.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Stephan Szabo @ 2002-01-04 08:19 UTC (permalink / raw)
  To: Bhuvan A <bhuvansql@yahoo.com>; +Cc: pgsql-sql

On Fri, 4 Jan 2002, Bhuvan A wrote:

> Well, now i would like to maintain modify_time for every updation. how
> can i? Using common plpgsql function i cant even able to refer OID
> even during UPDATION. The result is
>
> ERROR:  record old has no field oid
> 		or
> ERROR:  record new has no field oid
>
> One way: i can have seperate plpgsql function for every table and
> apply conditions accordingly. But i dont think thats the consistent
> way.
>
> how else can i maintain modify_time field ?

Would a before update trigger function something like:

begin
 NEW.modify_time=now();
 return NEW;
end;

do what you want?




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-01-04 08:19 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-04 06:47 maintaining a field for every UPDATION. Bhuvan A <bhuvansql@yahoo.com>
2002-01-04 08:19 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox