Re: [SQL] rule for update view that updates/inserts into 2 tables

2008-04-15 Thread Chad Showalter
7; as c FROM my_table t; Does this seem reasonable to you? Do you problems with this approach? Thanks again for your help, Chad From: Robins Tharakan [mailto:[EMAIL PROTECTED] Sent: Monday, April 14, 2008 8:34 PM To: Chad Showalter Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] r

Re: [SQL] rule for update view that updates/inserts into 2 tables

2008-04-14 Thread Robins Tharakan
Hi Chad, (Pardon me if I am shooting the stars here...) Don't you think that on each update, you would be creating a new row that satisfies that very given condition for the view ? By that I mean that when you do a 'UPDATE... WHERE my_table_id=1' the RULE now inserts another row with my_table_id

[SQL] rule for update view that updates/inserts into 2 tables

2008-04-14 Thread Chad Showalter
I would like to create a rule that, by updating a view, allows me to update one table and insert into another. The following example illustrates what I'm trying to do: --Create Tables CREATE TABLE my_table ( my_table_id serial, a character varying(255),

[SQL] Rule rewrite to possible union?

2007-12-06 Thread Erik Jones
Here's what I'd like to happen, but I'm not seeing how it can be done. Say we have this simple table: CREATE TABLE foo ( id integer, foo varchar ); and then many tables along these lines: CREATE TABLE ud1_foo (LIKE foo); CREATE TABLE ud2_foo (LIKE foo); What I'd like is to do is select agains

Re: [SQL] Rule Error

2007-10-04 Thread A. Kretschmer
am Fri, dem 05.10.2007, um 7:16:06 +0800 mailte Hengky Lie folgendes: > Yes, it works now ! Wow, the problem is in the field name. Changed it to > lowercase solved the problem. Thank you to all ho give me this advice. > > But now I have another question regarding to this field, what command I ca

Re: [SQL] Rule Error

2007-10-04 Thread Hengky Lie
between these 2 tables (tblmasdbt and tblmasgl) ? Thank you so much. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of A. Kretschmer Sent: 04 Oktober 2007 21:00 To: pgsql-sql@postgresql.org Subject: Re: [SQL] Rule Error am Thu, dem 04.10.2007, um 19:22:32

Re: [SQL] Rule Error

2007-10-04 Thread A. Kretschmer
am Thu, dem 04.10.2007, um 19:22:32 +0800 mailte Hengky Lie folgendes: > CREATE RULE "rule1" AS ON INSERT TO "public"."tblmasdbt" > > DO (insert into tblmasgl (KODEGL,NAMAREK) VALUES (new.KODEGL, new.NAMAREK)); > > > > But I always get this error : > > > ERROR: column "kodegl" of relation

Re: [SQL] Rule Error

2007-10-04 Thread Bart Degryse
You have defined the fields KODEGL and NAMAREK as uppercased field names. In your rule you refer to an unquoted field KODEGL twice and twice to an unquoted field NAMAREK. Default behaviour of PostgreSQL for unquoted fieldnames is to lowercase them. As such these fields effectively don't exist in y

Re: [SQL] Rule Error

2007-10-04 Thread Richard Huxton
Hengky Lie wrote: I have 2 tables : tblmasdbt and tblmasgl. I want on every record insertion in tblmasdbt, that record also automatically insert into tblmasdbt. I need only 2 related field. You probably want triggers rather than rules, but anyway. CREATE RULE "rule1" AS ON INSERT TO "publi

[SQL] Rule Error

2007-10-04 Thread Hengky Lie
Dear Friends, I have problem with rule and tried several times to solve it but not yet success. Hope someone can help me. I have 2 tables : tblmasdbt and tblmasgl. I want on every record insertion in tblmasdbt, that record also automatically insert into tblmasdbt. I need only 2 relate

Re: [SQL] Rule for multiple entries

2006-12-13 Thread Jim Buttafuoco
Subject: [SQL] Rule for multiple entries Hi all! I have a rule in place that is supposed to adjust a value in one table based on how many rows are added or deleted to another table, but I'm not getting the results that I hoped for. If a single sql statement adds or deletes multiple en

[SQL] Rule for multiple entries

2006-12-13 Thread William Scott Jordan
Hi all! I have a rule in place that is supposed to adjust a value in one table based on how many rows are added or deleted to another table, but I'm not getting the results that I hoped for. If a single sql statement adds or deletes multiple entries, the rule still only adjusts the value by

Re: [SQL] Rule causes baffling error

2005-12-20 Thread Richard Huxton
Ken Winter wrote: Richard ~ Let me zoom out for a moment, for the bigger picture. As you have inferred, what I'm trying to do is develop a history-preserving table ("my_data" in the example that started this thread). *Most* user programs would see and manipulate this table as if it contained o

Re: [SQL] Rule causes baffling error

2005-12-19 Thread Ken Winter
nks for your help. I hope this little essay is of some value to others. ~ Ken > -Original Message- > From: Richard Huxton [mailto:[EMAIL PROTECTED] > Sent: Monday, December 19, 2005 11:05 AM > To: Ken Winter > Cc: 'PostgreSQL pg-sql list' > Subject: Re: [SQL]

Re: [SQL] Rule causes baffling error

2005-12-19 Thread Tom Lane
Richard Huxton writes: > Ken Winter wrote: >> Can a trigger be written on a *view*? > There's nothing for them to fire against even if you could attach the > trigger. Currently we reject CREATE TRIGGER on a view, but it occurred to me the other day that that could be relaxed, at least for BEFOR

Re: [SQL] Rule causes baffling error

2005-12-19 Thread Richard Huxton
Ken Winter wrote: Richard ~ Thanks for your response. Can a trigger be written on a *view*? I can't find anything in the PostgreSQL docs that answers this question. There's nothing for them to fire against even if you could attach the trigger. I suppose you could have a statement-level trig

Re: [SQL] Rule causes baffling error

2005-12-19 Thread Ken Winter
ns was as rules. ~ Ken > -Original Message- > From: Richard Huxton [mailto:[EMAIL PROTECTED] > Sent: Monday, December 19, 2005 4:08 AM > To: Ken Winter > Cc: 'PostgreSQL pg-sql list' > Subject: Re: [SQL] Rule causes baffling error > > Ken Winter wrote: > >

Re: [SQL] Rule causes baffling error

2005-12-19 Thread Richard Huxton
Ken Winter wrote: This rule is supposed to (1) cause an update directed to the view "my_data_now" to be made to the underlying table "my_data", (2) reset the "effective_date_and_time" of that row to 'now', (3) insert a record containing the old values into "my_data", and (4) expire that "old" rec

[SQL] Rule causes baffling error

2005-12-16 Thread Ken Winter
I'm trying to figure out why a rule gives me a uniqueness violation when I try to do an update. I have a table, "my_data", defined as: create table my_data ( id INT8 not null default nextval('person_seq'), effective_date_and_time TIMESTAMP WITH TIME ZONE not null default CURRENT_T

[Fwd: RE: Re: [SQL] Rule]

2005-06-08 Thread Keith Worthington
Personally I feel that if this individual can't be bothered to white list the postgresql.org domain they should be banned from the list. Kind Regards, Keith Original Message Subject:RE: Re: [SQL] Rule Date: Wed, 8 Jun 2005 19:02:39 -0300 (BRT) From: AntiSpa

Re: [SQL] Rule

2005-06-08 Thread Keith Worthington
David wrote: What I want to do is setup some kind of rule so that whenever a s_data field is updated, that the time_stamp gets update to the current time/date. Normally you want to do that with a before trigger rather than a rule. Ok, I have no knowledge of Tiggers except what I just read i

Re: [SQL] Rule

2005-06-08 Thread David Hofmann
Ok, I have no knowledge of Tiggers except what I just read in the docs section. Look like I need to make a procudure then call it with a trigger. Is there a better location for Tigger/Procudure Examples. The trigger seems fairly, however I got lost in the procudure part. David Normally you

Re: [SQL] Rule

2005-06-08 Thread Bruno Wolff III
On Wed, Jun 08, 2005 at 15:51:35 -0400, David Hofmann <[EMAIL PROTECTED]> wrote: > > What I want to do is setup some kind of rule so that whenever a s_data > field is updated, that the time_stamp gets update to the current time/date. Normally you want to do that with a before trigger rather t

[SQL] Rule

2005-06-08 Thread David Hofmann
I have a table with 3 fields, id, s_data, and time_stamp. The time_stamp field is set to now() by deault. The program that uses this table only uses the id and s_data file. I added and use the time_stamp field to delete old records after a certain time. What I want to do is setup some kind

Re: [SQL] rule or trigger?

2005-06-07 Thread Richard Huxton
M.D.G. Lange wrote: In order for a "dictionary" system I have created the following system: tbllanguages - ID - name Primary key ( ID ) tbldictionary - wordid - languageid - value Primary key ( wordid, languageid) The idea is to have a word id in several languages, so you only have to look up

Re: [SQL] rule or trigger?

2005-06-07 Thread Stephan Szabo
On Tue, 7 Jun 2005, M.D.G. Lange wrote: > It is not possible to create a constraint Foreign key for "wordid". No > problem there, but I want to be certain that a given wordid exists in > tbldictionary. > Would I have to create a "RULE" or a "TRIGGER" to be certain that the > wordid is existing in

[SQL] rule or trigger?

2005-06-07 Thread M.D.G. Lange
In order for a "dictionary" system I have created the following system: tbllanguages - ID - name Primary key ( ID ) tbldictionary - wordid - languageid - value Primary key ( wordid, languageid) The idea is to have a word id in several languages, so you only have to look up the word id and give

Re: [SQL] RULE for mtime recording

2005-04-22 Thread Christoph Haller
Enrico Weigelt wrote: > > Hi folks, > > I'd like to write an update rule, which touches the a mtime field > (=current_timestamp) on normal update - when the mtime field isnt > explicitly set. If the update query explictly sets an mtime value, > this value has to be let through. > > my tables loo

[SQL] RULE for mtime recording

2005-04-21 Thread Enrico Weigelt
Hi folks, I'd like to write an update rule, which touches the a mtime field (=current_timestamp) on normal update - when the mtime field isnt explicitly set. If the update query explictly sets an mtime value, this value has to be let through. my tables look like: -- base class CREATE T

Re: [SQL] Rule problem with OLD / NEW record set

2005-02-07 Thread Christoph Haller
Ralph Graulich wrote: > > Hello everyone, > > given is a table with a version history kind of thing I am currently > working on. Upon this table there is a view and the application interacts > with the view only, updating/inserting/deleting is controlled by rules. It > seems like the record set "

[SQL] Rule problem with OLD / NEW record set

2005-01-26 Thread Ralph Graulich
Hello everyone, given is a table with a version history kind of thing I am currently working on. Upon this table there is a view and the application interacts with the view only, updating/inserting/deleting is controlled by rules. It seems like the record set "OLD" gets changed when it is used i

Re: [SQL] RULE and default nextval() column

2004-10-27 Thread Stephan Szabo
On Wed, 27 Oct 2004, Dmitry P. Ovechkin wrote: > Hello. > I'mtrying to implement history tables using rules. > I have > test_table > -- > create sequence history_seq start 1; > create sequence test_sequence; > # source table > drop table test_table; > create table test_table ( > i integer

[SQL] RULE and default nextval() column

2004-10-27 Thread Dmitry P. Ovechkin
Hello. I'mtrying to implement history tables using rules. I have test_table -- create sequence history_seq start 1; create sequence test_sequence; # source table drop table test_table; create table test_table ( i integer default nextval('test_sequence'), c character(10) ); # history table c

Re: [SQL] Rule won't let me NOTIFY, no matter how hard I try

2004-01-15 Thread Luis C. Ferreira
El Mar 13 Ene 2004 18:07, Jeff Boes escribió: >JB: Here's the setup: I wanted to write a rule that would fire on an update >JB: to one table, and do an update to another table, followed by a notify. >JB: My first attempt wasn't acceptable to PG (7.3.4): >JB: >JB: create rule "my_rule" as >JB: on up

[SQL] Rule won't let me NOTIFY, no matter how hard I try

2004-01-13 Thread Jeff Boes
Here's the setup: I wanted to write a rule that would fire on an update to one table, and do an update to another table, followed by a notify. My first attempt wasn't acceptable to PG (7.3.4): create rule "my_rule" as on update to table_A where new.col_A != old.col_A do (update table_B ...;

Re: [SQL] rule causes nextval() to be invoked twice

2003-07-23 Thread Dmitry Tkach
I think, your example would work if you replaced the new.id in the rule with curval ('main_id_seq'); ... but see Tom's earlier reply - this is still not a very good thing to do... For example, it won't work if you try to insert into main anything with explicitly specified id (not generated by th

Re: [SQL] rule causes nextval() to be invoked twice

2003-07-23 Thread A.Bhuvaneswaran
> Nevermind- that doesn't work either! Here's the new sample code: Rules are triggered before the event. You must do it in AFTER trigger. regards, bhuvaneswaran ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

Re: [SQL] rule causes nextval() to be invoked twice

2003-07-22 Thread Tom Lane
paul cannon <[EMAIL PROTECTED]> writes: > I'm having trouble understanding the behavior of rules with regards to > default values. > ... > If I remove the REFERENCES constraint, then I can see why. The insert > made into main behaves as expected; it gets nextval('main_id_seq'), > which comes out to

Re: [SQL] rule causes nextval() to be invoked twice

2003-07-22 Thread paul cannon
On Tue, Jul 22, 2003 at 07:47:00PM -0600, paul cannon wrote: > Until then, I'll have to make a function to do nextval('main_id_seq') > with every insert, and have the primary key be INTEGER. Nevermind- that doesn't work either! Here's the new sample code: -- Begin demo SQL CREATE SEQUENCE main_i

[SQL] rule causes nextval() to be invoked twice

2003-07-22 Thread paul cannon
'Sup list- I'm having trouble understanding the behavior of rules with regards to default values. Here's my situation: I have a table with a column referencing another. When inserts are made to the second, I would like a certain corresponding insert made to the first. Here's the simplest case I c

[SQL] Rule for updating through a view.

2003-03-21 Thread Mike Meyer
Ok, I found the documentation on using views to udpate the underlying database. But I can't seem to get my head around making it actually work, because updates may change only a few columns, and the columns in my views come from multiple tables. Could someone provide an example (CC'ing me, please,

Re: [SQL] Rule creation

2002-10-04 Thread Tom Lane
Edoardo Causarano <[EMAIL PROTECTED]> writes: > Hello, I need help on this rule: > CREATE RULE rule AS ON INSERT TO table WHERE (sum(new."field") > 10) DO > INSTEAD NOTHING; > Creation is ok but in inserting a row I get the following from pgaccessII > number -2147467259 > ERROR: fireRIRrules: fail

[SQL] Rule creation

2002-10-04 Thread Edoardo Causarano
Hello, I need help on this rule: CREATE RULE rule AS ON INSERT TO table WHERE (sum(new."field") > 10) DO INSTEAD NOTHING; Creation is ok but in inserting a row I get the following from pgaccessII number -2147467259 ERROR: fireRIRrules: failed to remove aggs from qual... Removing the INSTEAD from

Re: [SQL] Rule WHERE condition problem

2002-07-09 Thread Jan Wieck
Kristian Eide wrote: > > I have a table with a reference constraint and an ON DELETE SET NULL action. > When this action triggers, I also want to update another field in the table, > actually a timestamp which should be set to NOW(). > > After reading some documentation it would seem a rule is t

Re: [SQL] Rule WHERE condition problem

2002-07-09 Thread Kristian Eide
>> ERROR: query rewritten 10 times, may contain cycles >> It would seem that my WHERE clause is not checked before the action is run. >No, the WHERE clause is essentially transformed into part of the rule >query. You can't ever write a rule of the form > ON UPDATE TO b DO UPDATE b ... >bec

Re: [SQL] Rule WHERE condition problem

2002-07-09 Thread Tom Lane
"Kristian Eide" <[EMAIL PROTECTED]> writes: > ERROR: query rewritten 10 times, may contain cycles > It would seem that my WHERE clause is not checked before the action is run. No, the WHERE clause is essentially transformed into part of the rule query. You can't ever write a rule of the form

[SQL] Rule WHERE condition problem

2002-07-08 Thread Kristian Eide
I have a table with a reference constraint and an ON DELETE SET NULL action. When this action triggers, I also want to update another field in the table, actually a timestamp which should be set to NOW(). After reading some documentation it would seem a rule is the easiest way to accomplish this.

Re: [SQL] Rule problem

2002-06-13 Thread Tom Lane
Svenn Helge Grindhaug <[EMAIL PROTECTED]> writes: > create rule a_delete as > on delete to a do > delete from b where id1 = old.id1; > create rule c_delete as > on delete to c do > delete from a where id1 = (select id1 from b where id2 = old.id2); The a_delete rule is run before the actual "DELE

[SQL] Rule ON DELETE, to perform to DELETE querys !

2001-06-08 Thread Luis Sousa
I have a view over a join of tables and when it's performed over the view a delete i want to delete records in two different tables. The code that i wrote was: CREATE RULE "deletetables" AS ON DELETE TO "tables" DO INSTEAD ( DELETE FROM table2 WHERE id = OLD.

[SQL] RULE ... TO table.column

2001-04-16 Thread Albert REINER
Saluton, I am using , | SELECT version(); | version | | PostgreSQL 7.0.2 on i586-pc-linux-gnulibc1, compiled by gcc 2.95.1 | (1 row) ` , and upgrading to 7.1 is not possible (it was hard

Re: [SQL] Rule/currval() issue

2001-03-14 Thread Tom Lane
"Creager, Robert S" <[EMAIL PROTECTED]> writes: > You indicate trigger, rather than rule. Going by Momjian's book, he > indicates that rules are "...ideal for when the action affects other > tables." Can you clarify why you would use a trigger for this? Primarily because there's a need to get a

RE: [SQL] Rule/currval() issue

2001-03-14 Thread Creager, Robert S
due > Cc: [EMAIL PROTECTED] > Subject: Re: [SQL] Rule/currval() issue > > > Tim Perdue <[EMAIL PROTECTED]> writes: > > This is related to the plpgsql project I was working on > this morning. I'm > > trying to create a rule, so that when a row is inser

Re: [SQL] Rule/currval() issue

2001-03-14 Thread Tom Lane
Tim Perdue <[EMAIL PROTECTED]> writes: >> You probably should be using a trigger, not a rule at all. > OK - so another rule like this one, is probably ill-advised as well? It seems > a lot easier than going into the triggers: > CREATE RULE forum_delete_agg AS > ON DELETE TO forum > DO UP

Re: [SQL] Rule/currval() issue

2001-03-14 Thread Tim Perdue
On Wed, Mar 14, 2001 at 01:09:18PM -0500, Tom Lane wrote: > Tim Perdue <[EMAIL PROTECTED]> writes: > > This is related to the plpgsql project I was working on this morning. I'm > > trying to create a rule, so that when a row is inserted into a certain table, > > we also create a row over in a "cou

Re: [SQL] Rule/currval() issue

2001-03-14 Thread Tom Lane
Tim Perdue <[EMAIL PROTECTED]> writes: > This is related to the plpgsql project I was working on this morning. I'm > trying to create a rule, so that when a row is inserted into a certain table, > we also create a row over in a "counter table". The problem lies in getting > the primary key value (

Re: [SQL] Rule/currval() issue

2001-03-14 Thread Andrew Perrin
Entirely untested, but how about replacing currval() in your first try with nextval()? My theory is that the compilation of the function is happening before the INSERT happens; therefore the sequence hasn't been incremented yet; therefore there's no currval() for this backend instance. If you use

[SQL] Rule/currval() issue

2001-03-14 Thread Tim Perdue
This is related to the plpgsql project I was working on this morning. I'm trying to create a rule, so that when a row is inserted into a certain table, we also create a row over in a "counter table". The problem lies in getting the primary key value (from the sequence) so it can be inserted in tha

Re: [SQL] Rule not invoked in 7.1

2001-01-26 Thread Jan Wieck
Kyle wrote: > The only complication is > that there are a class of records which the user should be able to view, but not > modify. For example, > the employee can create and modify working records as long as the only > modification to their status > is to move them on to "open status" (creating

Re: [SQL] Rule not invoked in 7.1

2001-01-26 Thread Kyle
Jan Wieck wrote: > Tom Lane wrote: > > > This might be better done with a trigger than a rule. For one thing, > > a trigger can easily raise an exception. MHO is that rules are good > > when you need to update multiple rows in other tables when certain > > things happen. If you just want to va

Re: [SQL] Rule not invoked in 7.1

2001-01-26 Thread Kyle
Tom Lane wrote: Kyle <[EMAIL PROTECTED]> writes: > If someone happens to know the primary key of a record they should not be > able to access, and they try to update it, I would like the backend to > ignore the query (or better yet, raise an exception but I haven't figured > out how to do that). 

Re: [SQL] Rule not invoked in 7.1

2001-01-26 Thread Kyle
Tom Lane wrote: > Kyle <[EMAIL PROTECTED]> writes: > > If someone happens to know the primary key of a record they should not be > > able to access, and they try to update it, I would like the backend to > > ignore the query (or better yet, raise an exception but I haven't figured > > out how to

Re: [SQL] Rule not invoked in 7.1

2001-01-26 Thread Jan Wieck
Tom Lane wrote: > Kyle <[EMAIL PROTECTED]> writes: > > If someone happens to know the primary key of a record they should not be > > able to access, and they try to update it, I would like the backend to > > ignore the query (or better yet, raise an exception but I haven't figured > > out how to d

Re: [SQL] Rule not invoked in 7.1

2001-01-25 Thread Kyle
Jan Wieck wrote: Tom Lane wrote: > Kyle <[EMAIL PROTECTED]> writes: > > ERROR:  Cannot update a view without an appropriate rule. > > 7.1 insists that you provide an *unconditional* DO INSTEAD rule > for a view.  What do you think was happening on your old database > when the "where old.status =

Re: [SQL] Rule not invoked in 7.1

2001-01-25 Thread Jan Wieck
Tom Lane wrote: > Kyle <[EMAIL PROTECTED]> writes: > > ERROR: Cannot update a view without an appropriate rule. > > 7.1 insists that you provide an *unconditional* DO INSTEAD rule > for a view. What do you think was happening on your old database > when the "where old.status = 'appr'" clause was

Re: [SQL] Rule not invoked in 7.1

2001-01-24 Thread Tom Lane
Kyle <[EMAIL PROTECTED]> writes: > ERROR: Cannot update a view without an appropriate rule. 7.1 insists that you provide an *unconditional* DO INSTEAD rule for a view. What do you think was happening on your old database when the "where old.status = 'appr'" clause wasn't satisfied? Nothing good

[SQL] Rule not invoked in 7.1

2001-01-24 Thread Kyle
I have a number of views that seemed to work fine in 7.0.3.  When I try to do an update to these views under 7.1, I get the following error: ERROR:  Cannot update a view without an appropriate rule. For example, there's a view that looks like this: create view pay_req_v_prl as select empl_id,wdat