pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Акулов Александр <akulov@ien.ru>
To: pgsql-sql@postgresql.org
Subject: Can I create working trigger on view
Date: Thu, 17 Oct 2002 18:40:30 +0400
Message-ID: <9736000265.20021017184030@ien.ru> (raw)

Hello!
Please, help me!

Can I create working trigger on view?

The problem is:
  I need a plpgsql function that execute on insert (or update,
  or delete) into view and knows the *OLD* and *NEW*.
  (Number of fields can be more than 16)
    
Something like this:

  Create Sequence id;
  Create Table t1(id1 int4, last_name varchar(32), time_create_t1);
  Create Table t2(id2 int4, first_name varchar(32), time_create_t2);
  Create View name as
    Select * from t1 a, t2 b where a.id1=b.id2;
  Create Rule rl_ins_nameas on INSERT to name do instead nothing;
  -- without it trigger is not allowed
  Create Function fn_ins_name() returns opaque as
  '
  Declare
    v_time_create timestamp;
  Begin
    v_tm_create:=current_timestamp;
    Insert into t1(id1, last_name, time_create_t1)
            values(nextval(''id''), new.last_name, v_time_create);
    Insert into t2(id2, first_name, time_create_t2)
            values(currval(''id''), new.first_name, v_time_create);
    return null;
  End;
  ' Language 'plpgsql';
  Create Trigger tr_ins_name before INSERT on now_cis_user
  for each row execute procedure fn_ins_name;
  
  This example is very simple. The trigger is not fired.

Sorry for my English.
--
Thanks for everybody.
Akulov Alexander.

e-mail:akulov@ien.ru




view thread (4+ messages)  latest in thread

Message-ID: <9736000265.20021017184030@ien.ru>
Permalink:  ../9736000265.20021017184030@ien.ru/
Also on:    postgresql.org/message-id/9736000265.20021017184030@ien.ru

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: akulov@ien.ru
  Subject: Re: Can I create working trigger on view
  In-Reply-To: <9736000265.20021017184030@ien.ru>

* 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