[SQL] detect initiator of update/delete action

2013-09-20 Thread ssylla
Dear list, I want to create a function on a table that does something before deletion on a table, e.g. like create or replace function table1_del() returns trigger as $$ begin update table1 set column1= substr(column2,1,10); insert into table1_hist values (

Re: [SQL] detect initiator of update/delete action

2013-09-20 Thread Luca Ferrari
On Fri, Sep 20, 2013 at 9:52 AM, ssylla wrote: > There are two cases: > 1. if the deletion was executed through a user action, both the update and > insert statement of the 'table1_del' function should be executed > 2. if the deletion was initiated through a function fired from another > table, on

[SQL] unique key problem on update

2013-09-20 Thread Gary Stainburn
Hi folks. I've got the table and data shown below. I want to add a new page after page 2 so I try to increase the sequence number of each row from page 3 onwards to make space in the sequence for the new record. However, I get duplicate key errors when I try. Can anyone suggest how I get roun

[SQL] the value of OLD on an initial row insert

2013-09-20 Thread James Sharrett
I have a number of trigger functions on a table that are performing various calculations. The table is a column-wise orientation with multiple columns that could be updated on a single row. In one of the triggers, I'm performing a calculation but don't want the code to run if the OLD and NEW valu

Re: [SQL] unique key problem on update

2013-09-20 Thread Gary Stainburn
On Friday 20 September 2013 17:26:58 Thomas Kellerer wrote: > You need to define the primary key as deferrable: > > create table skills_pages > ( > sp_idserial not null, > sp_sequence integer not null, > sp_title character varying(80), > sp_narative text, > primary key (sp_i

Re: [SQL] unique key problem on update

2013-09-20 Thread Thomas Kellerer
Gary Stainburn wrote on 20.09.2013 18:30: You need to define the primary key as deferrable: create table skills_pages ( sp_idserial not null, sp_sequence integer not null, sp_title character varying(80), sp_narative text, primary key (sp_id) deferrable ); Cheers. I

Re: [SQL] unique key problem on update

2013-09-20 Thread Thomas Kellerer
Gary Stainburn wrote on 20.09.2013 18:07: I want to add a new page after page 2 so I try to increase the sequence number of each row from page 3 onwards to make space in the sequence for the new record. However, I get duplicate key errors when I try. Can anyone suggest how I get round this. Also