pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jan Wieck <janwieck@Yahoo.com>
To: Jie Liang <jliang@ipinc.com>
Cc: Jyotsna Kypa <jkypa@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Need your help
Date: Mon, 26 Feb 2001 12:14:18 -0500 (EST)
Message-ID: <200102261714.MAA03268@jupiter.jw.home> (raw)
In-Reply-To: <Pine.BSF.4.10.10102231253570.58909-100000@tidal.ipinc.com>

Jie Liang wrote:
> e.g.
> Try:
>
> CREATE TABLE emp (
>     id int4 primary key,
>     empname text,
>     salary int4,
>     last_date datetime,
>     last_user name);
>
> CREATE FUNCTION emp_stamp () RETURNS OPAQUE AS
>     BEGIN
>    update emp set last_date=''now''::timestamp where id=NEW.id;
>         RETURN NEW;
>     END;
> ' LANGUAGE 'plpgsql';
>
> CREATE TRIGGER emp_stamp BEFORE UPDATE ON emp
>     FOR EACH ROW EXECUTE PROCEDURE emp_stamp();

    Not  sure  if it works this way at all, but the update on emp
    table is definitely a wasted scan. And  the  'now'::timestamp
    will  be  evaluated at the first function call - never again;
    not sure if he wanted that behaviour either.

        CREATE FUNCTION emp_stamp () RETURNS opaque AS '
        BEGIN
            new.last_date := now();
            RETURN new;
        END;'
        LANGUAGE 'plpgsql';

    Is the correct trigger for this purpose.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




view thread (3+ messages)

Message-ID: <200102261714.MAA03268@jupiter.jw.home>
Permalink:  ../200102261714.MAA03268@jupiter.jw.home/
Also on:    postgresql.org/message-id/200102261714.MAA03268@jupiter.jw.home

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: janwieck@Yahoo.com, jliang@ipinc.com, jkypa@yahoo.com
  Subject: Re: Need your help
  In-Reply-To: <200102261714.MAA03268@jupiter.jw.home>
  References: <Pine.BSF.4.10.10102231253570.58909-100000@tidal.ipinc.com> <200102261714.MAA03268@jupiter.jw.home>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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