dbTalk Databases Forums  

Re: triggers

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: triggers in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Iandé Coutinho
 
Posts: n/a

Default Re: triggers - 04-16-2004 , 09:22 AM






thanks Colin, that worked just great!!

----- Original Message -----
From: "Colin Gillespie" <C.Gillespie (AT) newcastle (DOT) ac.uk>
To: "Iandé Coutinho" <iande (AT) br (DOT) inter.net>; <pgsql-novice (AT) postgresql (DOT) org>
Sent: Friday, April 16, 2004 10:51 AM
Subject: RE: [NOVICE] triggers


Hi Iande,

Try this

DROP TABLE t1 CASCADE;
CREATE TABLE t1
(
id serial,
branch integer NOT NULL,
uniqueid integer
);

DROP FUNCTION insert_uniqueid();
CREATE FUNCTION insert_uniqueid() RETURNS trigger AS'
BEGIN
NEW.uniqueid:= NEW.id||NEW.branch;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';

CREATE TRIGGER insert_uniqueid BEFORE INSERT
ON t1 FOR EACH ROW EXECUTE
PROCEDURE insert_uniqueid();

Colin


-----Original Message-----
From: pgsql-novice-owner (AT) postgresql (DOT) org on behalf of Iandé Coutinho
Sent: Fri 4/16/2004 2:17 PM
To: pgsql-novice (AT) postgresql (DOT) org
Subject: Fw: [NOVICE] triggers

Anyone??
----- Original Message -----
From: "Iandé Coutinho" <iande (AT) br (DOT) inter.net>
To: <pgsql-novice (AT) postgresql (DOT) org>
Sent: Thursday, April 15, 2004 3:49 PM
Subject: [NOVICE] triggers


Afternoon guys, I would be very gratefull if anyone could help me on this
one. I´ve tried looking for examples on it, i know it´s simple, but i can´t
get one, so here goes. I need to create a trigger(after insert), preferebly
in plpgsql, as I have already created the lang using createlang, that, takes
value from 2 columns of the record it´s inserting, and concatenate together
and insert it into a 3rd column,
for example:

I have a table:

employee

id | branch | name | uniqueId
---|--------|-------|---------

on insert into employee(id,branch,name) values(1,1543,"iande");

the trigger would get both id and branch valeus and insert on uniqueId
so,

select * from employee;

id | branch | name | uniqueId
-----------------------------
1 | 1543 | iande | 15431


thanks in advance;

Iandé






---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster




---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.