![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello list, I've a table where I want a UPDATE performed if the primary key that should be inserted already exists, but which performs a INSERT if the primary key does not exist. It doesn't really work. Here's what I have: CREATE RULE nonexistent_insert_crit_hosts AS ON UPDATE TO crit_hosts WHERE (new.host) NOT IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD INSERT INTO crit_hosts (host, properties) VALUES (new.host, new.properties); CREATE RULE duplicate_update_crit_hosts AS ON INSERT TO crit_hosts WHERE (new.host) IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD UPDATE crit_hosts SET properties = new.properties WHERE host = new.host; Upon UPDATE with a non-existing primary key leads to: ERROR: infinite recursion spotted in rules for relation »crit_hosts« ' in 'UPDATE crit_hosts SET properties = properties | B'00000000000000000000000000000001' WHERE host = '192.168.1.3';' (the error message is translated from German so it might well be a little different in the original) What am I doing wrong? on INSERT you do UPDATE, on UPDATE do INSERT, on INSERT do UPDATE, on |
|
Thanks in advance, Johannes If you want do such thing create a view on a table and create rules on |
#3
| |||
| |||
|
|
Hello list, I've a table where I want a UPDATE performed if the primary key that should be inserted already exists, but which performs a INSERT if the primary key does not exist. It doesn't really work. Here's what I have: CREATE RULE nonexistent_insert_crit_hosts AS ON UPDATE TO crit_hosts WHERE (new.host) NOT IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD INSERT INTO crit_hosts (host, properties) VALUES (new.host, new.properties); CREATE RULE duplicate_update_crit_hosts AS ON INSERT TO crit_hosts WHERE (new.host) IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD UPDATE crit_hosts SET properties = new.properties WHERE host = new.host; Upon UPDATE with a non-existing primary key leads to: ERROR: infinite recursion spotted in rules for relation »crit_hosts« ' in 'UPDATE crit_hosts SET properties = properties | B'00000000000000000000000000000001' WHERE host = '192.168.1.3';' (the error message is translated from German so it might well be a little different in the original) What am I doing wrong? on INSERT you do UPDATE, on UPDATE do INSERT, on INSERT do UPDATE, on |
|
Thanks in advance, Johannes If you want do such thing create a view on a table and create rules on |
#4
| |||
| |||
|
|
Hello list, I've a table where I want a UPDATE performed if the primary key that should be inserted already exists, but which performs a INSERT if the primary key does not exist. It doesn't really work. Here's what I have: CREATE RULE nonexistent_insert_crit_hosts AS ON UPDATE TO crit_hosts WHERE (new.host) NOT IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD INSERT INTO crit_hosts (host, properties) VALUES (new.host, new.properties); CREATE RULE duplicate_update_crit_hosts AS ON INSERT TO crit_hosts WHERE (new.host) IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD UPDATE crit_hosts SET properties = new.properties WHERE host = new.host; Upon UPDATE with a non-existing primary key leads to: ERROR: infinite recursion spotted in rules for relation »crit_hosts« ' in 'UPDATE crit_hosts SET properties = properties | B'00000000000000000000000000000001' WHERE host = '192.168.1.3';' (the error message is translated from German so it might well be a little different in the original) What am I doing wrong? on INSERT you do UPDATE, on UPDATE do INSERT, on INSERT do UPDATE, on |
|
Thanks in advance, Johannes If you want do such thing create a view on a table and create rules on |
#5
| |||
| |||
|
|
Hello list, I've a table where I want a UPDATE performed if the primary key that should be inserted already exists, but which performs a INSERT if the primary key does not exist. It doesn't really work. Here's what I have: CREATE RULE nonexistent_insert_crit_hosts AS ON UPDATE TO crit_hosts WHERE (new.host) NOT IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD INSERT INTO crit_hosts (host, properties) VALUES (new.host, new.properties); CREATE RULE duplicate_update_crit_hosts AS ON INSERT TO crit_hosts WHERE (new.host) IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD UPDATE crit_hosts SET properties = new.properties WHERE host = new.host; Upon UPDATE with a non-existing primary key leads to: ERROR: infinite recursion spotted in rules for relation »crit_hosts« ' in 'UPDATE crit_hosts SET properties = properties | B'00000000000000000000000000000001' WHERE host = '192.168.1.3';' (the error message is translated from German so it might well be a little different in the original) What am I doing wrong? on INSERT you do UPDATE, on UPDATE do INSERT, on INSERT do UPDATE, on |
|
Thanks in advance, Johannes If you want do such thing create a view on a table and create rules on |
#6
| |||
| |||
|
|
Hello list, I've a table where I want a UPDATE performed if the primary key that should be inserted already exists, but which performs a INSERT if the primary key does not exist. It doesn't really work. Here's what I have: CREATE RULE nonexistent_insert_crit_hosts AS ON UPDATE TO crit_hosts WHERE (new.host) NOT IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD INSERT INTO crit_hosts (host, properties) VALUES (new.host, new.properties); CREATE RULE duplicate_update_crit_hosts AS ON INSERT TO crit_hosts WHERE (new.host) IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD UPDATE crit_hosts SET properties = new.properties WHERE host = new.host; Upon UPDATE with a non-existing primary key leads to: ERROR: infinite recursion spotted in rules for relation »crit_hosts« ' in 'UPDATE crit_hosts SET properties = properties | B'00000000000000000000000000000001' WHERE host = '192.168.1.3';' (the error message is translated from German so it might well be a little different in the original) What am I doing wrong? on INSERT you do UPDATE, on UPDATE do INSERT, on INSERT do UPDATE, on |
|
Thanks in advance, Johannes If you want do such thing create a view on a table and create rules on |
#7
| |||
| |||
|
|
Hello list, I've a table where I want a UPDATE performed if the primary key that should be inserted already exists, but which performs a INSERT if the primary key does not exist. It doesn't really work. Here's what I have: CREATE RULE nonexistent_insert_crit_hosts AS ON UPDATE TO crit_hosts WHERE (new.host) NOT IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD INSERT INTO crit_hosts (host, properties) VALUES (new.host, new.properties); CREATE RULE duplicate_update_crit_hosts AS ON INSERT TO crit_hosts WHERE (new.host) IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD UPDATE crit_hosts SET properties = new.properties WHERE host = new.host; Upon UPDATE with a non-existing primary key leads to: ERROR: infinite recursion spotted in rules for relation »crit_hosts« ' in 'UPDATE crit_hosts SET properties = properties | B'00000000000000000000000000000001' WHERE host = '192.168.1.3';' (the error message is translated from German so it might well be a little different in the original) What am I doing wrong? on INSERT you do UPDATE, on UPDATE do INSERT, on INSERT do UPDATE, on |
|
Thanks in advance, Johannes If you want do such thing create a view on a table and create rules on |
#8
| |||
| |||
|
|
Hello list, I've a table where I want a UPDATE performed if the primary key that should be inserted already exists, but which performs a INSERT if the primary key does not exist. It doesn't really work. Here's what I have: CREATE RULE nonexistent_insert_crit_hosts AS ON UPDATE TO crit_hosts WHERE (new.host) NOT IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD INSERT INTO crit_hosts (host, properties) VALUES (new.host, new.properties); CREATE RULE duplicate_update_crit_hosts AS ON INSERT TO crit_hosts WHERE (new.host) IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD UPDATE crit_hosts SET properties = new.properties WHERE host = new.host; Upon UPDATE with a non-existing primary key leads to: ERROR: infinite recursion spotted in rules for relation »crit_hosts« ' in 'UPDATE crit_hosts SET properties = properties | B'00000000000000000000000000000001' WHERE host = '192.168.1.3';' (the error message is translated from German so it might well be a little different in the original) What am I doing wrong? on INSERT you do UPDATE, on UPDATE do INSERT, on INSERT do UPDATE, on |
|
Thanks in advance, Johannes If you want do such thing create a view on a table and create rules on |
#9
| |||
| |||
|
|
Hello list, I've a table where I want a UPDATE performed if the primary key that should be inserted already exists, but which performs a INSERT if the primary key does not exist. It doesn't really work. Here's what I have: CREATE RULE nonexistent_insert_crit_hosts AS ON UPDATE TO crit_hosts WHERE (new.host) NOT IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD INSERT INTO crit_hosts (host, properties) VALUES (new.host, new.properties); CREATE RULE duplicate_update_crit_hosts AS ON INSERT TO crit_hosts WHERE (new.host) IN (SELECT host FROM crit_hosts WHERE host = new.host) DO INSTEAD UPDATE crit_hosts SET properties = new.properties WHERE host = new.host; Upon UPDATE with a non-existing primary key leads to: ERROR: infinite recursion spotted in rules for relation »crit_hosts« ' in 'UPDATE crit_hosts SET properties = properties | B'00000000000000000000000000000001' WHERE host = '192.168.1.3';' (the error message is translated from German so it might well be a little different in the original) What am I doing wrong? on INSERT you do UPDATE, on UPDATE do INSERT, on INSERT do UPDATE, on |
|
Thanks in advance, Johannes If you want do such thing create a view on a table and create rules on |
![]() |
| Thread Tools | |
| Display Modes | |
| |