Re: Can I create a trigger to add another record based on the inserted record in the same table?

From: David Johnston <polobo(at)yahoo(dot)com>
To: Mohd Shaiza Ibrahim <mohdshaiza(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Can I create a trigger to add another record based on the inserted record in the same table?
Date: 2012-07-18 12:37:30
Message-ID: 5174807D-CA35-4CE2-B03E-77BC4A515695@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Jul 17, 2012, at 20:59, Mohd Shaiza Ibrahim <mohdshaiza(at)gmail(dot)com> wrote:

> Hi,
>
> Can you guys please help me? My question sounds like this.
>
> When I insert a new record in a table, can I create a trigger to add
> another record based on the inserted record in the same table?
>
> For example,
>
> INSERT INTO employee (emp_id, emp_name) VALUES (0001, 'Jack');
>
> The result:
>
> Select * from employee;
>
> emp_id | emp_name
> 0001 | Jack
> 0002 | Bob
>
> I've tried running the statement below but it doesn't work. Infinite
> loop i'm guessing.
>
>

Infinite loop is correct. You need to fix your logic to solve that problem or consider a new design. Maybe restrict inserts to the table to a security definer function and put you dual insert logic into it.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2012-07-18 12:46:35 Re: Can I create a trigger to add another record based on the inserted record in the same table?
Previous Message Radosław Smogura 2012-07-18 09:00:25 Re: Can't reset password