Re: [SQL] Trigger

2000-09-06 Thread Chris Ryan

Craig May wrote:
> 
> Could someone send me a quick example of a trigger.

Hope this helps.

Chris Ryan

<<< Clip below and execute to create example >>>
--
-- FUNCTION: trigger_last_updated
--
-- DESCRIPTION:
-- This is a function called by the table triggers to update the
last_updated
-- field on insert and updates.
--
create function trigger_last_updated()
returns opaque
as 'begin
new.last_updated := now();
return new;
end;'
language 'plpgsql';

--
-- TABLE: test_tbl
--
-- DESCRIPTION:
-- A simple table to test my trigger
--
create table test_tbl (
some_field varchar(10),
last_updated timestamp not null default now()
);

--
-- TRIGGER: trigger_insert_update_test_tbl
--
-- DESCRIPTION:
-- This is the trigger called on insert and updates of all the table
that
-- has the last_updated field. It will use the function
trigger_last_updated
-- The cool thing here is the function doesn't make specific reference
to the
-- table so you could create a different trigger for each table with the
field
-- last_updated and use the same function.
--
create trigger trigger_insert_update_test_tbl
before insert or update on test_tbl
for each row execute procedure trigger_last_updated();



Re: [SQL] Trigger

2000-09-06 Thread Chris Ryan

Chris Ryan wrote:
> 
> Craig May wrote:
> >
> > Could someone send me a quick example of a trigger.
> 
> Hope this helps.
> 
> Chris Ryan
> 
 -- snipped code --

I am so sorry but you may have noticed my email client wrapped lines it
shouldn't have. I have attached the file this time.

Chris Ryan

--
-- FILE: trigger_example.sql
--
-- DESCRIPTION:
-- This file shows the basics of creating a table with a trigger
--
-- Chris Ryan <[EMAIL PROTECTED]> 09/06/2000
--
-- GENERAL DISCLAIMER:
-- Please feel free to use this in any way you see fit to copy, modify,
-- redistribute, etc.. I provide not warranty of the code nor may I be held
-- responsible for it's use/misuse should something bad happen including
-- intentional or acts of god.
--

--
-- FUNCTION: trigger_last_updated
--
-- DESCRIPTION:
-- This is a function called by the table triggers to update the last_updated
-- field on insert and updates.
--
create function trigger_last_updated()
returns opaque
as 'begin
new.last_updated := now();
return new;
end;'
language 'plpgsql';

--
-- TABLE: test_tbl
--
-- DESCRIPTION:
-- A simple table to test my trigger
--
create table test_tbl (
some_field varchar(10),
last_updated timestamp not null default now()
);

--
-- TRIGGER: trigger_insert_update_test_tbl
--
-- DESCRIPTION:
-- This is the trigger called on insert and updates of all the table that
-- has the last_updated field. It will use the function trigger_last_updated
-- The cool thing here is the function doesn't make specific reference to the
-- table so you could create a different trigger for each table with the field
-- last_updated and use the same function.
--
create trigger trigger_insert_update_test_tbl
before insert or update on test_tbl
for each row execute procedure trigger_last_updated();



[SQL] [Fwd: [Gborg-bugs] BUG: reference error when using inherited tables (ID: 269) (new)]

2001-05-16 Thread Chris Ryan

I received this bug on a project I administer that Isn't related to my
project. I forwarded it here to see if any of you could help this
person.


[EMAIL PROTECTED] wrote:
> 
> Title: reference error when using inherited tables
> Bug Type: Software bug
> Severity: Serious
> Software Version: Other
> Environment: k6III-500/394
> SuSE 7.1
> Postgres 7.1
> 
> Created By: gorefest
> Description: Hi
> 
> I have a problem with inherited refences.
> For example :
> CREATE TABLE A(LNR integer Primary key  blabla);
> CREATE TABLE B () INHERITS(A);
> CREATE TABLE C(LNR integer primary key blabla, RNR Intger not null, unique(RNR), 
>FOREIGN KEY(RNR) REFERENCES A.LNr ON DELETE CASCADE);
> 
> will throw an error, if i try to insert an object into B with a counterpart in C. A 
>with a counterpart in C works. Due to the fact, that the inheritance is an acyclic 
>graph, the machine should look in B to. But i get a reference error instead. Are 
>references on inherited tables not implemented yet ?
> 
> greetings gorefest
> Status: Submitted
> 
> http://www.greatbridge.org/project/gborg/bugs/bugupdate.php?269
> 
> ___
> Gborg-bugs mailing list
> [EMAIL PROTECTED]
> http://www.greatbridge.org/mailman/listinfo/gborg-bugs

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]