Re: [SQL] Trigger for updating view with join

2013-09-03 Thread Dmitry Morozovsky
Heh, it's me spamming you again :) now -- asking for comments. > > create trigger fsl_update instead of insert or update on fsl ... > > > > but till now did not succeed in it. Quick googlink did not help either. > > Argh. My google-fu is definitely low in the night ;) > > for the record: it'

Re: [SQL] Trigger for updating view with join

2013-09-03 Thread Dmitry Morozovsky
On Wed, 4 Sep 2013, Dmitry Morozovsky wrote: > Dear colleagues, > > I'm running Pg 9.1 and have schema like the following: [snip] > I understand I should use smth like > > create trigger fsl_update instead of insert or update on fsl ... > > but till now did not succeed in it. Quick googlink

[SQL] Trigger for updating view with join

2013-09-03 Thread Dmitry Morozovsky
Dear colleagues, I'm running Pg 9.1 and have schema like the following: create table machines ( mid serial not null primary key, mname text not null unique ); create table fs ( fsidserial not null primary key, mid int not null references machines,

Re: [SQL] Trigger triggered from a foreign key

2012-10-22 Thread Jasen Betts
On 2012-10-19, Victor Sterpu wrote: > I have this trigger that works fine. The trigger prevents the deletion > of the last record. > But I want skip this trigger execution when the delete is done from a > external key. > How can I do this? perhaps you have to use a rule instead of a trigger? -

Re: [SQL] Trigger triggered from a foreign key

2012-10-19 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Victor Sterpu > Sent: Friday, October 19, 2012 2:15 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] Trigger triggered from a foreign key > >

[SQL] Trigger triggered from a foreign key

2012-10-19 Thread Victor Sterpu
I have this trigger that works fine. The trigger prevents the deletion of the last record. But I want skip this trigger execution when the delete is done from a external key. How can I do this? This is the fk ALTER TABLE focgdepartment ADD CONSTRAINT fk_focgdep_idfocg FOREIGN KEY (idfocg)

[SQL] Trigger: update if record exists

2011-05-09 Thread Tarlika Elisabeth Schmitz
I wrote a trigger function to convert inserts into updates if the record exists already. - I am not using rules because the table is populated via COPY. - I am employing a two-stage process (PERFORM, then UPDATE) because the update trigger might decide not to update after all, and therefore FOUND

Re: [SQL] [TRIGGER] Returning values from BEFORE UPDATE trigger, without using them

2010-07-27 Thread Torsten Zühlsdorff
Tom Lane schrieb: =?ISO-8859-15?Q?Torsten_Z=FChlsdorff?= writes: I have defined an BEFORE UPDATE trigger. The trigger catch every update, change some columns of the new row, make an insert of the new row and returns null to abort the update. Why in the world would you do that? Just return t

Re: [SQL] [TRIGGER] Returning values from BEFORE UPDATE trigger, without using them

2010-07-27 Thread Tom Lane
=?ISO-8859-15?Q?Torsten_Z=FChlsdorff?= writes: > I have defined an BEFORE UPDATE trigger. The trigger catch every update, > change some columns of the new row, make an insert of the new row and > returns null to abort the update. Why in the world would you do that? Just return the modified row

Re: [SQL] [TRIGGER] Returning values from BEFORE UPDATE trigger, without using them

2010-07-26 Thread Torsten Zühlsdorff
Hey Dmitriy, thanks for your reply. I think, its would be better to use rule on update instead of the trigger in such case as you. I've played the whole weekend with the rule-system, but it didn't work for my case. I have a dynamic trigger, which takes cares about revision of rows for every

[SQL] [TRIGGER] Returning values from BEFORE UPDATE trigger, without using them

2010-07-23 Thread Torsten Zühlsdorff
Hello, i have a non-trival problem and i do not believe that it is solvable. I have defined an BEFORE UPDATE trigger. The trigger catch every update, change some columns of the new row, make an insert of the new row and returns null to abort the update. All fine till here :) Now the problem:

Re: [SQL] [Trigger] Help needed with NEW.* and TG_TABLE_NAME

2010-05-17 Thread Torsten Zühlsdorff
Jasen Betts schrieb: On 2010-05-11, Torsten Zühlsdorff wrote: Hello, i have a problem with a trigger written in pl/pgsql. It looks like this: CREATE OR REPLACE FUNCTION versionize() RETURNS TRIGGER AS $$ BEGIN NEW.revision := addContentRevision (OLD.content_id, OLD.revision); /* not

Re: [SQL] [Trigger] Help needed with NEW.* and TG_TABLE_NAME

2010-05-13 Thread Jasen Betts
On 2010-05-11, Torsten Zühlsdorff wrote: > Hello, > > i have a problem with a trigger written in pl/pgsql. > > It looks like this: > > CREATE OR REPLACE FUNCTION versionize() > RETURNS TRIGGER > AS $$ > BEGIN > >NEW.revision := addContentRevision (OLD.content_id, OLD.revision); > >/* not w

Re: [SQL] [Trigger] Help needed with NEW.* and TG_TABLE_NAME

2010-05-11 Thread silly sad
On 05/11/10 18:26, Torsten Zühlsdorff wrote: Tom Lane schrieb: =?ISO-8859-15?Q?Torsten_Z=FChlsdorff?= writes: NEW.revision := addContentRevision (OLD.content_id, OLD.revision); /* not working line, just a stub: EXECUTE 'INSERT INTO ' || TG_TABLE_NAME || ' SELECT $1 ' USING NEW; */ RETU

Re: [SQL] [Trigger] Help needed with NEW.* and TG_TABLE_NAME

2010-05-11 Thread Stuart
Torsten, Usually, the “insert ... (select ...)” has the select portion enclosed in parenthesis. Don't know if solution is that simple but did not see it in your examples. It may be worth a try. Stuart - Original message - > Hello, > > i have a problem with a trigger written in pl/pgs

[SQL] [Trigger] Help needed with NEW.* and TG_TABLE_NAME

2010-05-11 Thread Torsten Zühlsdorff
Hello, i have a problem with a trigger written in pl/pgsql. It looks like this: CREATE OR REPLACE FUNCTION versionize() RETURNS TRIGGER AS $$ BEGIN NEW.revision := addContentRevision (OLD.content_id, OLD.revision); /* not working line, just a stub: EXECUTE 'INSERT INTO ' || TG_TABLE_NAM

Re: [SQL] [Trigger] Help needed with NEW.* and TG_TABLE_NAME

2010-05-11 Thread Torsten Zühlsdorff
Tom Lane schrieb: =?ISO-8859-15?Q?Torsten_Z=FChlsdorff?= writes: NEW.revision := addContentRevision (OLD.content_id, OLD.revision); /* not working line, just a stub: EXECUTE 'INSERT INTO ' || TG_TABLE_NAME || ' SELECT $1 ' USING NEW; */ RETURN NULL; This seems like the

Re: [SQL] [Trigger] Help needed with NEW.* and TG_TABLE_NAME

2010-05-11 Thread Tom Lane
=?ISO-8859-15?Q?Torsten_Z=FChlsdorff?= writes: >NEW.revision := addContentRevision (OLD.content_id, OLD.revision); >/* not working line, just a stub: >EXECUTE 'INSERT INTO ' || TG_TABLE_NAME || ' SELECT $1 ' USING NEW; >*/ >RETURN NULL; This seems like the hard way. Why do

[SQL] [Trigger] Help needed with NEW.* and TG_TABLE_NAME

2010-05-11 Thread Torsten Zühlsdorff
Hello, i have a problem with a trigger written in pl/pgsql. It looks like this: CREATE OR REPLACE FUNCTION versionize() RETURNS TRIGGER AS $$ BEGIN NEW.revision := addContentRevision (OLD.content_id, OLD.revision); /* not working line, just a stub: EXECUTE 'INSERT INTO ' || TG_TABLE_NAM

[SQL] [Trigger] Help needed with NEW.* and TG_TABLE_NAME

2010-05-11 Thread Torsten Zühlsdorff
Hello, i have a problem with a trigger written in pl/pgsql. It looks like this: CREATE OR REPLACE FUNCTION versionize() RETURNS TRIGGER AS $$ BEGIN NEW.revision := addContentRevision (OLD.content_id, OLD.revision); /* not working line, just a stub: EXECUTE 'INSERT INTO ' || TG_TABLE_NAM

Re: [SQL] Trigger on select :-(

2010-03-11 Thread Jaime Casanova
On Mon, Mar 1, 2010 at 9:10 PM, Ray Madigan wrote: > > What I want to do is when I do a SELECT on the Catalog and deliver the > result to the user, I want to check to see if the FooKey is in the users > ToDo table and set the value of a column isToDo to true or false depending > on if the FooKey e

Re: [SQL] Trigger on select :-(

2010-03-11 Thread Garrett Murphy
@postgresql.org] On Behalf Of Ray Madigan Sent: Monday, March 01, 2010 7:11 PM To: pgsql-sql@postgresql.org Subject: [SQL] Trigger on select :-( What I want is to have a trigger on select, but since I have searched the archives I know that is not possible. I also read that view rules is the tech

[SQL] Trigger on select :-(

2010-03-11 Thread Ray Madigan
What I want is to have a trigger on select, but since I have searched the archives I know that is not possible. I also read that view rules is the technology is whats available. Having never used views before I can't seem to get my mind to figure out what I need to do to solve my problem. I have

Re: [SQL] trigger failed to identify the partions

2009-09-09 Thread Richard Huxton
Sridhar Reddy Ratna wrote: > > cmd := 'INSERT INTO ' || dateTable || > EXECUTE cmd; > RETURN NEW; > If I changed the RETURN NEW to RETURN NULL its inserting only one row. Yes. RETURN NEW allows the insert to procede normally so you end up with the two rows. > But to work wi

Re: [SQL] trigger failed to identify the partions

2009-09-09 Thread Sridhar Reddy Ratna
Sridhar ratna -Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Richard Huxton Sent: Wednesday, September 09, 2009 3:35 PM To: Sridhar Reddy Ratna Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] trigger failed to

Re: [SQL] trigger failed to identify the partions

2009-09-09 Thread Richard Huxton
Sridhar Reddy Ratna wrote: > > dateTable := coll_fp_subdtls_01; > > ELSE > > dateTable := coll_fp_subdtls_02; > ERROR: column "coll_fp_subdtls_01" does not exist > > ERROR: column "coll_fp_subdtls_01" does not exist I think you mi

[SQL] trigger failed to identify the partions

2009-09-09 Thread Sridhar Reddy Ratna
Hi all, I have created a table and partitions as below. CREATE TABLE coll_fp_submission_details ( rrid numeric NOT NULL, sid numeric NOT NULL, pfid numeric NOT NULL, "timestamp" date NOT NULL, schema_version numeric NOT NULL, details character varying NOT NULL, app_

[SQL] trigger problem

2009-08-06 Thread Jan Verheyden
Hi, If I try this to run in a trigger function 'perform dblink_connect('myconnect','dbname=postgres password=uzleuven'); perform dblink_exec('myconnect', 'insert into test (uid) values (' || quote_literal(NEW.pat_id) || ')'); return new; perform dblink_disconnect('myconnect');' I get the mess

Re: [SQL] trigger before delete question

2009-04-21 Thread Tom Lane
Sigrid Thijs writes: > I've bumped into a problem with a trigger before delete that I do not > immediately understand. I have made a simple example that also illustrates > the issue, but in reality the database structure is more complex. The reason it doesn't work is that the delete from member c

[SQL] trigger before delete question

2009-04-21 Thread Sigrid Thijs
Hello, I've bumped into a problem with a trigger before delete that I do not immediately understand. I have made a simple example that also illustrates the issue, but in reality the database structure is more complex. Here's the database scheme: create table club ( club_id serial n

Re: [SQL] Trigger/Function - one solution - was constraint question (I think)

2008-12-04 Thread Rafael Domiciano
I would develop like this (No so many changes, it is basically a small trigger) create or replace function compound_rows_range_check() returns trigger as $body$ DECLARE BAYNO int4; BEGIN -- First Verification = if changing compound or row fail IF (old.co_id <> new.co_id or old.cr_id <>

Re: [SQL] Trigger/Function - one solution - was constraint question (I think)

2008-12-04 Thread Gary Stainburn
I have managed to develop one solution using functions and triggers. Has anyone got a better solution? Gary create unique index "compound_bays_unique_index" on compound_bays using btree (co_id,cr_id,cb_id); create or replace function compound_rows_range_check() returns trigger as $proc$ DECLA

Re: [SQL] trigger parameters, what am I doing wrong ??

2008-10-10 Thread Bart Degryse
With some version (but I don't remember which) I had the same problem. I solved it by assigning TG_ARGV[0] to a variable and use the variable in the RAISE NOTICE. >>> Tom Lane <[EMAIL PROTECTED]> 2008-10-09 19:22 >>> "Marcin Krawczyk" <[EMAIL PROTECTED]> writes: > And here's what RAISE NOTICE lo

Re: [SQL] trigger parameters, what am I doing wrong ??

2008-10-09 Thread Tom Lane
"Marcin Krawczyk" <[EMAIL PROTECTED]> writes: > And here's what RAISE NOTICE looks like : NOTICE: TG_ARGV = , > TG_NARGS = 0, par = > What's wrong with it ?? I'm running 8.1.4 Works for me: regression=# insert into test_table values(1); INSERT 0 1 regression=# update test_table set f1 = 2; NOTI

[SQL] trigger parameters, what am I doing wrong ??

2008-10-09 Thread Marcin Krawczyk
Hi guys. I'm trying to pass a parameter to trigger procedure but it's not working and I have no idea why since it looks pretty ok. Here's what I do : CREATE OR REPLACE FUNCTION test_proc() RETURNS "trigger" AS $BODY$ DECLARE chk boolean; parinteger := TG_ARGV[0]; BEGIN RAISE NOTICE 'TG_

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2008-09-17 Thread Raphael Bauduin
On Wed, Sep 17, 2008 at 5:45 PM, hubert depesz lubaczewski <[EMAIL PROTECTED]> wrote: > On Wed, Sep 17, 2008 at 05:08:39PM +0200, Raphael Bauduin wrote: >> Would you have a little example on how you would do it? > > show us what you have done - it will be easier to find/fix/explain than > to write

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2008-09-17 Thread Raphael Bauduin
HI, On Sat, Aug 11, 2007 at 9:07 PM, hubert depesz lubaczewski <[EMAIL PROTECTED]> wrote: > On Sat, Aug 11, 2007 at 02:45:09AM -0500, Javier Fonseca V. wrote: >> I think that it's working alright except for the next line: > > doing this in plpgsql is very complicated (or even impossible assuming >

Re: [SQL] trigger for TRUNCATE?

2008-01-14 Thread Peter Childs
On 11/01/2008, Simon Riggs <[EMAIL PROTECTED]> wrote: > > On Fri, 2008-01-11 at 08:24 +, Richard Huxton wrote: > > > I've always considered TRUNCATE to be DDL rather than DML. I mentally > > group it with DROP TABLE rather than DELETE> > > DDL/DML probably isn't the right split, since its then

Re: [SQL] trigger for TRUNCATE?

2008-01-11 Thread Bruce Momjian
Added to TODO: > * Add ability to trigger on TRUNCATE > > http://archives.postgresql.org/pgsql-sql/2008-01/msg00050.php --- Simon Riggs wrote: > On Fri, 2008-01-11 at 08:24 +, Richard Huxton wrote: > > > I've always

Re: [SQL] trigger for TRUNCATE?

2008-01-11 Thread Simon Riggs
On Fri, 2008-01-11 at 08:24 +, Richard Huxton wrote: > I've always considered TRUNCATE to be DDL rather than DML. I mentally > group it with DROP TABLE rather than DELETE> DDL/DML probably isn't the right split, since its then arguable as to which group of commands it belongs in. I see we

Re: [SQL] trigger for TRUNCATE?

2008-01-11 Thread Erik Jones
On Jan 11, 2008, at 2:24 AM, Richard Huxton wrote: Tom Lane wrote: Alvaro Herrera <[EMAIL PROTECTED]> writes: My thinking is that a TRUNCATE trigger is a per-statement trigger which doesn't have access to the set of deleted rows (Replicator uses it that way -- we replicate the truncate act

Re: [SQL] trigger for TRUNCATE?

2008-01-11 Thread Richard Huxton
Tom Lane wrote: Alvaro Herrera <[EMAIL PROTECTED]> writes: My thinking is that a TRUNCATE trigger is a per-statement trigger which doesn't have access to the set of deleted rows (Replicator uses it that way -- we replicate the truncate action, and replay it on the replica). In that way it would

Re: [SQL] trigger for TRUNCATE?

2008-01-10 Thread Chris Browne
[EMAIL PROTECTED] (Tom Lane) writes: > Alvaro Herrera <[EMAIL PROTECTED]> writes: >> Gerardo Herzig escribió: >>> Yes, the TRUNCATE statement is not sql ansi, maybe is a more low level >>> thing than i think. > >> TRUNCATE currently does not fire triggers, but that doesn't mean it's >> impossible

Re: [SQL] trigger for TRUNCATE?

2008-01-10 Thread Simon Riggs
Alvaro Herrera wrote: > My thinking is that a TRUNCATE trigger is a per-statement trigger which > doesn't have access to the set of deleted rows. > In that way it would be different from a per-statement trigger for > DELETE. Completely agree. A truncate trigger should run a different function

Re: [SQL] trigger for TRUNCATE?

2008-01-10 Thread Tom Lane
Alvaro Herrera <[EMAIL PROTECTED]> writes: > My thinking is that a TRUNCATE trigger is a per-statement trigger which > doesn't have access to the set of deleted rows (Replicator uses it that > way -- we replicate the truncate action, and replay it on the replica). > In that way it would be differen

Re: [SQL] trigger for TRUNCATE?

2008-01-10 Thread Gerardo Herzig
Tom Lane wrote: Alvaro Herrera <[EMAIL PROTECTED]> writes: Gerardo Herzig escribió: Yes, the TRUNCATE statement is not sql ansi, maybe is a more low level thing than i think. TRUNCATE currently does not fire triggers, but that doesn't mean it's impossible to do it. I thin

Re: [SQL] trigger for TRUNCATE?

2008-01-10 Thread Alvaro Herrera
Tom Lane escribió: > Alvaro Herrera <[EMAIL PROTECTED]> writes: > > Gerardo Herzig escribi�: > >> Yes, the TRUNCATE statement is not sql ansi, maybe is a more low level > >> thing than i think. > > > TRUNCATE currently does not fire triggers, but that doesn't mean it's > > impossible to do it. I

Re: [SQL] trigger for TRUNCATE?

2008-01-10 Thread Tom Lane
Alvaro Herrera <[EMAIL PROTECTED]> writes: > Gerardo Herzig escribió: >> Yes, the TRUNCATE statement is not sql ansi, maybe is a more low level >> thing than i think. > TRUNCATE currently does not fire triggers, but that doesn't mean it's > impossible to do it. I think it would be fairly easy to

Re: [SQL] trigger for TRUNCATE?

2008-01-10 Thread Alvaro Herrera
Gerardo Herzig escribió: > Yes, the TRUNCATE statement is not sql ansi, maybe is a more low level > thing than i think. TRUNCATE currently does not fire triggers, but that doesn't mean it's impossible to do it. I think it would be fairly easy to add support for that. Currently, Mammoth Replica

Re: [SQL] trigger for TRUNCATE?

2008-01-10 Thread Gerardo Herzig
Pavel Stehule wrote: On 08/01/2008, Chris Browne <[EMAIL PROTECTED]> wrote: [EMAIL PROTECTED] (Gerardo Herzig) writes: Hi all. Acording to the docs, TRUNCATE will not fire a DELETE trigger on the table being truncated. There is a way to capture a TRUNCATE in any way? I think th

Re: [SQL] trigger for TRUNCATE?

2008-01-08 Thread Pavel Stehule
Hello theoretically you can have trigger on any statement, but I am not sure about conformance with std. But, you can wrap TRUNCATE statement into some procedure, and then call this procedure with some other actions. Regards Pavel Stehule On 08/01/2008, Chris Browne <[EMAIL PROTECTED]> wrote: >

Re: [SQL] trigger for TRUNCATE?

2008-01-08 Thread Chris Browne
[EMAIL PROTECTED] (Gerardo Herzig) writes: > Hi all. Acording to the docs, TRUNCATE will not fire a DELETE trigger > on the table being truncated. > There is a way to capture a TRUNCATE in any way? I think there's some sort of "to do" on that... It ought to be not *too* difficult (I imagine!) to

[SQL] trigger for TRUNCATE?

2008-01-08 Thread Gerardo Herzig
Hi all. Acording to the docs, TRUNCATE will not fire a DELETE trigger on the table being truncated. There is a way to capture a TRUNCATE in any way? Thanks! Gerardo ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] Trigger definition . . . puzzled

2007-12-13 Thread Rolf A. de By
Ouch, that hurts! It suddenly dawns on me . . . Big difference on table that you specify and table where it actually takes effect. Confusing at first. Thanks a million, Tom. "Rolf A. de By" <[EMAIL PROTECTED]> writes: Yes, this is an inheritance set-up. But actually no: I am executing al

Re: [SQL] Trigger definition . . . puzzled

2007-12-13 Thread Tom Lane
"Rolf A. de By" <[EMAIL PROTECTED]> writes: > Yes, this is an inheritance set-up. But actually no: I am executing all > my data changes against the parent table, and want the trigger on that > parent table to fire for an insert on the parent table as it does. But > I also want the trigger to f

Re: [SQL] Trigger definition . . . puzzled

2007-12-13 Thread Rolf A. de By
Thanks Tom, Yes, this is an inheritance set-up. But actually no: I am executing all my data changes against the parent table, and want the trigger on that parent table to fire for an insert on the parent table as it does. But I also want the trigger to fire when an update on the parent table

Re: [SQL] Trigger definition . . . puzzled

2007-12-13 Thread Tom Lane
"Rolf A. de By" <[EMAIL PROTECTED]> writes: > Thanks for that. There is some misunderstanding here. For this example, > I had taken the sting out of my trigger function and turned it into a > much more concise no-op, with warnings. The actual code of my original > trigger function is irrelevan

Re: [SQL] Trigger definition . . . puzzled

2007-12-12 Thread Rolf A. de By
Erik, Thanks for that. There is some misunderstanding here. For this example, I had taken the sting out of my trigger function and turned it into a much more concise no-op, with warnings. The actual code of my original trigger function is irrelevant. The no-op trigger function displays the

Re: [SQL] Trigger definition . . . puzzled

2007-12-12 Thread Erik Jones
On Dec 12, 2007, at 3:38 PM, Rolf A. de By wrote: Greetings list, Running pg 8.2.3. on a windows machine, I have become blind in a trigger definition puzzle, so hope that somebody may help me understand where I goof. I have a base table i_s that has three tables that inherit from it,

[SQL] Trigger definition . . . puzzled

2007-12-12 Thread Rolf A. de By
Greetings list, Running pg 8.2.3. on a windows machine, I have become blind in a trigger definition puzzle, so hope that somebody may help me understand where I goof. I have a base table i_s that has three tables that inherit from it, one of them being i_s_nowhere. The base table should be

Re: [SQL] Trigger to change different row in same table

2007-09-04 Thread PostgreSQL Admin
chester c young wrote: > how are you preventing recursion? > > That could be the problem, suggestions? ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

[SQL] Trigger to change different row in same table

2007-09-04 Thread PostgreSQL Admin
I want to write a trigger that updates a different row on the same table. It's pretty basic: before the any row in his table updated I want to set a only row that has the value true to false. I keep getting this error: SQL statement "update theirry.articles set master_featured = false where mast

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread hubert depesz lubaczewski
On Sat, Aug 11, 2007 at 02:45:09AM -0500, Javier Fonseca V. wrote: > I think that it's working alright except for the next line: doing this in plpgsql is very complicated (or even impossible assuming that any table can have the same trigger). i would rather suggest using pl/perl - writing somethin

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Javier Fonseca V.
Yes Tom, you're right, but the real problem is that I need to use an EXECUTE statement because my table name is dynamic. In your example, you used logt as a static table name, and that doesn't need an EXECUTE statement. So I think that I'll have to rewrite a Trigger Procedure for each table and t

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Pavel Stehule
2007/8/11, Tom Lane <[EMAIL PROTECTED]>: > "Pavel Stehule" <[EMAIL PROTECTED]> writes: > > NEW is only plpgsql variable. It isn't visible on SQL level. > > Correct, but: > > > You cannot use new.*, you can: > > execute 'INSERT ...' || 'VALUES(' || new.a || ',' || new.b > > You're both overthin

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Tom Lane
"Pavel Stehule" <[EMAIL PROTECTED]> writes: > NEW is only plpgsql variable. It isn't visible on SQL level. Correct, but: > You cannot use new.*, you can: > execute 'INSERT ...' || 'VALUES(' || new.a || ',' || new.b You're both overthinking the problem. In recent releases (at least since 8.

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Pavel Stehule
NEW is only plpgsql variable. It isn't visible on SQL level. You cannot use new.*, you can: execute 'INSERT ...' || 'VALUES(' || new.a || ',' || new.b regards Pavel 2007/8/11, Javier Fonseca V. <[EMAIL PROTECTED]>: > > > Hello. > > I'm doing a Trigger Procedure in pl/pgSQL. It makes some k

[SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Javier Fonseca V.
Hello. I'm doing a Trigger Procedure in pl/pgSQL. It makes some kind of auditing. I think that it's working alright except for the next line: EXECUTE 'INSERT INTO ' || quote_ident(somedynamictablename) || ' SELECT new.*'; PostgreSQL keeps telling me: "ERROR: NEW used in query that is not in a

Re: [SQL] trigger firing order

2007-06-15 Thread chester c young
> > does the post trigger on A wait until post trigger on B is > executed? -> > this seems intuitive to me. > > How can it wait until the trigger on B is executed if the trigger on > B doesn't > actually get triggered until someone updates B and it's the trigger > on A > doing the update? trigge

Re: [SQL] trigger firing order

2007-06-15 Thread Gregory Stark
"chester c young" <[EMAIL PROTECTED]> writes: > tables A and B: a post row trigger on A cause updates on B which has > its own post row trigger. > > does the post trigger on A wait until post trigger on B is executed? - > this seems intuitive to me. How can it wait until the trigger on B is execu

[SQL] trigger firing order

2007-06-15 Thread chester c young
tables A and B: a post row trigger on A cause updates on B which has its own post row trigger. does the post trigger on A wait until post trigger on B is executed? - this seems intuitive to me. does the post trigger on B wait until the trigger on A has completed? or is post trigger A launched as

Re: [SQL] Trigger with Stored Procedure [Client Points]

2006-08-31 Thread Aaron Bono
On 8/31/06, Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> wrote: Bono,I must check each insert on my Points(each shop generate a new line on Points table).When I insert  the  record  on points  I must  see the field Value(on points table already) and update the Client.Points field based in some

Re: [SQL] Trigger with Stored Procedure [Client Points]

2006-08-31 Thread Aaron Bono
On 8/30/06, Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> wrote: Hi list,I have a table like this:Points-Idoperationvalueand another two tables like thisClient    Rule    -

Re: [SQL] Trigger on Insert to Update only newly inserted fields?

2006-08-31 Thread Aaron Bono
On 8/28/06, Henry Ortega <[EMAIL PROTECTED]> wrote: Here's what I am doing:I have this table:employee   payrate     effective     tstamp   end_date (to be updated by trigger)jdoe   1000 04-01-2006    2006-03-10 13:39: 07.614945jdoe

[SQL] Trigger with Stored Procedure [Client Points]

2006-08-30 Thread Ezequias Rodrigues da Rocha
Hi list,I have a table like this:Points-Idoperationvalueand another two tables like thisClient    Rule    ---id idname 

Re: [SQL] Trigger on Insert to Update only newly inserted fields?

2006-08-29 Thread Michael Fuhr
On Mon, Aug 28, 2006 at 11:53:36AM -0400, Henry Ortega wrote: > CREATE FUNCTION updated_end_date() RETURNS trigger AS ' > BEGIN >update table set end_date=(select effective-1 from table t2 where > t2.employee=table.employee and t2.effective>table.effective order by > t2.effective limit 1); >

Re: [SQL] Trigger on Insert to Update only newly inserted fields?

2006-08-28 Thread Henry Ortega
Here's what I am doing:I have this table:employee   payrate     effective     tstamp   end_date (to be updated by trigger)jdoe   1000 04-01-2006    2006-03-10 13:39: 07.614945jdoe   1500 04-01-2006    2006-03-12 15:

Re: [SQL] Trigger on Insert to Update only newly inserted fields?

2006-08-28 Thread Michael Fuhr
On Mon, Aug 28, 2006 at 10:02:32AM -0400, Henry Ortega wrote: > I have a On Insert Trigger that updates one of the columns in that same > table. > > Is there a way for the trigger to run only for the newly inserted records? > Instead of all records in the database? Row-level INSERT and UPDATE trig

[SQL] Trigger on Insert to Update only newly inserted fields?

2006-08-28 Thread Henry Ortega
I have a On Insert Trigger that updates one of the columns in that same table.Is there a way for the trigger to run only for the newly inserted records? Instead of all records in the database?E.g.:ID      Start_Date End_Date 001   08-01-2006    002   08-02-2006On Insert/Update, Update End_Date=

Re: [SQL] trigger needs to check in multiple tables.

2006-08-18 Thread Michael Fuhr
On Fri, Aug 18, 2006 at 07:17:27PM +0200, Jacobo Garca wrote: > I'm running a simple query inside a function that is associated with a > trigger: > >SELECT tipo INTO tipocuenta FROM producto WHERE codigo_cuenta= > NEW.codigo_destino; > > I am getting this error when running the code on pgadmi

[SQL] trigger needs to check in multiple tables.

2006-08-18 Thread Jacobo García
Hello.I'm running a simple query inside a function that is associated with a trigger:    SELECT tipo INTO tipocuenta FROM producto WHERE codigo_cuenta=NEW.codigo_destino ;I am getting this error when running the code on pgadmin IIIERROR:  NEW used in query that is not in a rule QUERY:  SELECT  tipo

Re: [SQL] Trigger, record "old" is not assigned yet

2006-07-13 Thread Aaron Bono
On 7/13/06, Adrian Klaver <[EMAIL PROTECTED]> wrote: For plpgsql use TG_OP. See link below.http://www.postgresql.org/docs/8.1/interactive/plpgsql-trigger.htmlOn Thursday 13 July 2006 03:50 pm, Daniel Caune wrote: > Hi, I've created a trigger BEFORE INSERT OR UPDATE on a table and, indeed,> when

Re: [SQL] Trigger, record "old" is not assigned yet

2006-07-13 Thread Adrian Klaver
For plpgsql use TG_OP. See link below. http://www.postgresql.org/docs/8.1/interactive/plpgsql-trigger.html On Thursday 13 July 2006 03:50 pm, Daniel Caune wrote: > Hi, > > > > I've created a trigger BEFORE INSERT OR UPDATE on a table and, indeed, > when the trigger is raised before insertion the re

[SQL] Trigger, record "old" is not assigned yet

2006-07-13 Thread Daniel Caune
Hi,   I’ve created a trigger BEFORE INSERT OR UPDATE on a table and, indeed, when the trigger is raised before insertion the record “old” is not assigned.  Is there a way to distinguish in the trigger procedure from an insert statement to an update statement?   Regards,     -- Danie

Re: [SQL] trigger to enforce FK with nulls?

2006-04-12 Thread Stephan Szabo
On Wed, 12 Apr 2006, George Young wrote: > [PostgreSQL 8.1.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.0.1] > > I'm starting to use lots of foreign key constraints to keep my > data clean. In one case, however, I need to allow null values > for the key. E.g.: > > create table opset_steps

Re: [SQL] trigger to enforce FK with nulls?

2006-04-12 Thread Alvaro Herrera
George Young wrote: > Since foreign keys per se can't do this, I presume the way > is to use triggers, though I have not used triggers before. Says who? Just don't specify NOT NULL on the referencing column. -- Alvaro Herrerahttp://www.CommandPrompt.com/ The Pos

[SQL] trigger to enforce FK with nulls?

2006-04-12 Thread George Young
[PostgreSQL 8.1.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.0.1] I'm starting to use lots of foreign key constraints to keep my data clean. In one case, however, I need to allow null values for the key. E.g.: create table opset_steps(opset text, step text, step_num int); create table st

Re: [SQL] Trigger/Sequence headache

2006-02-17 Thread rlee0001
Stephen, You don't need to use a seperate batch to clean up the table. As Stephan pointed out, you can call nextval after you determine that the new row isn't a duplicate. In case you misunderstood what Stephan had suggested let me try to explain what is happening. When PostgreSQL receives an IN

Re: [SQL] Trigger/Sequence headache

2006-02-14 Thread Markus Schaber
Hi, Stephen, Foster, Stephen wrote: > That's what I thought was going to be the answer. I was just hoping I > was making a mistake somehow. It's no big deal but I like things > organized and hate giant holes. > > Ok, one more thing for one of the batch jobs. No problem I have a > cleanup routi

Re: [SQL] Trigger/Sequence headache

2006-02-12 Thread Foster, Stephen
Lee Foster/ -Original Message- From: Stephan Szabo [mailto:[EMAIL PROTECTED] Sent: Sunday, February 12, 2006 5:11 PM To: Foster, Stephen Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Trigger/Sequence headache On Sun, 12 Feb 2006, Foster, Stephen wrote: > This is going to be one of those stupi

Re: [SQL] Trigger/Sequence headache

2006-02-12 Thread Stephan Szabo
On Sun, 12 Feb 2006, Foster, Stephen wrote: > This is going to be one of those stupid problems of mine. I have an > insert trigger setup to verify that duplicate or repeating information > isn't storage in the table. If trigger function finds the information > as a duplicate it returns a NULL a

[SQL] Trigger/Sequence headache

2006-02-12 Thread Foster, Stephen
This is going to be one of those stupid problems of mine.  I have an insert trigger setup to verify that duplicate or repeating information isn’t storage in the table.  If trigger function finds the information as a duplicate it returns a NULL and the information isn’t added; that works.  T

Re: [SQL] Trigger efficiency

2006-02-06 Thread Craig Servin
I do not know of a way to make your trigger run less often, but you could only have it do the insert if something changes. This is what we do: CREATE or replace FUNCTION UPDATE_SERVER_HST() RETURNS TRIGGER AS ' begin if (OLD.ADD_DATE is distinct from NEW.ADD_DATE or OLD.HOSTNAME

[SQL] Trigger efficiency

2006-02-06 Thread Josep Sanmartí
Hi, I've the following problem and I don't know how to solve it: There is a table with about 10-12 fields, a couple of those fields are updated very often (about 30 times / minute or even more). This is my table (more or less): crete table monitor( time Timestamp, time2 timestamp, .

Re: [SQL] Trigger on a column

2006-02-06 Thread Richard Huxton
Josep Sanmartí wrote: Hi, readding around I just found this: The CREATE TRIGGER statement in PostgreSQL implements a subset of the SQL99 standard. (There are no provisions for triggers in SQL92.) The following functionality IS MISSING: * SQL99 allows triggers to fire on updates to specific col

Re: [SQL] Trigger on a column

2006-02-06 Thread Josep Sanmartí
Hi, readding around I just found this: The CREATE TRIGGER statement in PostgreSQL implements a subset of the SQL99 standard. (There are no provisions for triggers in SQL92.) The following functionality IS MISSING: * SQL99 allows triggers to fire on updates to specific columns (e.g., AFTER UPDA

[SQL] Trigger on a column

2006-02-06 Thread Josep Sanmartí
Hi, My trigger's running on a table that works perfectly. This trigger calls a function that inserts or modifies a row of a different table. My problem is that I need to optimize this trigger, and the only way that I've found is to fire the trigger when certain table fields are modified. I

[SQL] Trigger for Large Object Modification

2006-01-15 Thread Andreas Roth
Hello, I created a table with a OID Column to carry the identifier for a Large Object. Now i want to run a trigger is the data of the large object has changed. To do this I created an ON UPDATE-trigger on the table, but the trigger does get fired if i only change the data of the large object (

Re: [SQL] Trigger / rule question

2005-11-20 Thread Joost Kraaijeveld
Hi Peter, On Sun, 2005-11-20 at 12:08 +0100, Peter Eisentraut wrote: > Joost Kraaijeveld wrote: > > 1. Does an insert, update or delete statement return before or after > > an "After" trigger (is such a trigger or rule synchronous or > > a-synchronous? > > Synchronous > > > 2. Is there a concept

Re: [SQL] Trigger / rule question

2005-11-20 Thread Peter Eisentraut
Joost Kraaijeveld wrote: > 1. Does an insert, update or delete statement return before or after > an "After" trigger (is such a trigger or rule synchronous or > a-synchronous? Synchronous > 2. Is there a concept of a rule or trigger that fails? > If so, if a trigger or rule fails, does the inser

  1   2   3   >