Inserting Data

From: Bob Pawley <rjpawley(at)shaw(dot)ca>
To: Postgresql <pgsql-general(at)postgresql(dot)org>
Subject: Inserting Data
Date: 2006-08-18 16:27:19
Message-ID: 011301c6c2e3$3aaed960$8e904618@owner
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi All

I have a basic problem that I hope can be addressed.

I need to insert data from one table into three other tables.

I attempted the following format.

CREATE OR REPLACE FUNCTION p_id_monitor()
RETURNS "trigger" AS
$$
Begin
insert into p_id.loops (monitor)
Select p_id.devices.devices_id
Where p_id.devices.device_number = library.devices.device_number
and library.devices.type_ = 'mon' ;

insert into p_id.settings (monitor)
Select p_id.devices.devices_id
Where p_id.devices.device_number = library.devices.device_number
and library.devices.type_ = 'mon' ;

insert into p_id.alarms (monitor)
Select p_id.devices.devices_id
Where p_id.devices.device_number = library.devices.device_number
and library.devices.type_ = 'mon' ;

Return Null ;
End;
$$
LANGUAGE 'plpgsql' ;
create trigger mon after insert on p_id.devices
for each row execute procedure p_id_monitor() ;

Unfortunately this gave multiple results on the target tables.

Is there a format that will give me a single insert for each original field without the need of creating three triggers???

Bob

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2006-08-18 18:20:15 Re: Migrating PostgreSQL database to MySQL/MS Access
Previous Message Michael Meskes 2006-08-18 16:01:02 Re: Connection string