triggers

postgresql trigger with dblink doesn't return anything

◇◆丶佛笑我妖孽 提交于 2019-12-24 01:54:06
问题 I created a trigger to replicate inserts from a table 'mytable_db1' in database1 into the same table 'mytable_db2' on database2. Both databases are on the same server. CREATE OR REPLACE FUNCTION trigger_osm_test_insert() RETURNS trigger AS $BODY$ BEGIN PERFORM dblink_connect('db2', 'dbname=xxx port=5432 user=myusr password=xxx'); PERFORM dblink_exec('db2', 'insert into test.mytable_db2 (osm_id, name, name_eng, name_int, type, z_order, population, last_update, country, iso3, shape) values ('|

DDL Trigger which grants permission to new created users

北城余情 提交于 2019-12-24 01:49:18
问题 I got a question, is there a possibilty, that a DDL Trigger can grant roles right after the user is created. For example: CREATE OR REPLACE TRIGGER DDL_TRIGGER AFTER CREATE ROLE ON DATABASE And after that, the trigger should grant the new user with some roles. For example: BEGIN GRANT Resourse to *new created user*; GRANT CONNECT to *new created user*; I use oracle database. Thank you guys, Marki 回答1: I think it should be this one: CREATE OR REPLACE TRIGGER T_CREATE_USER AFTER CREATE ON

jquery keypress event to trigger autocomplete only on specific keycodes

主宰稳场 提交于 2019-12-24 01:25:45
问题 I am using the jquery autocomplete plugin, and am trying to trigger the autocomplete manually based on certain keys the user enters. I'm trying to bind the autocomplete to the input on the fly so the autocomplete can start looking for matches once a user enters a certain key to trigger "I'm now entering data to be searched on", which could be in the middle of the field, not necessarily at the beginning. I'm binding a keypress event to an input. When the user enters a certain key, like "=", I

How to Store MySQL Trigger exception / failure info into Table or in Variables

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 01:13:12
问题 I am stuck at somewhere and I need some help from you. Scenario I have two databases i.e., test_db1 and test_db2 and have users table on both of them. Both databases initially are empty (0 rows). Here's users table schema: DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `id` int(11) AUTO_INCREMENT, `name` varchar(30) NOT NULL, `age` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; After that, I have written some triggers for INSERT , UPDATE and

Oracle Trigger to update a the same table

拟墨画扇 提交于 2019-12-24 00:24:54
问题 I have a trigger which I'm trying to use to update the same table it listens to. However, upon submitting a create or update, I get the following errors: ORA-04091: table [username].ADDRESSES is mutating, trigger/function may not see it ORA-06512: at "[username].ADDRESSES_T1", line 9 ORA-04088: error during execution of trigger '[username].ADDRESSES_T1' I appreciate any help! 回答1: You're updating the same table the trigger is written. You need something like this: create or replace trigger

Are the 'inserted' and 'deleted' tables guaranteed to return their records in the same order in an AFTER UPDATE trigger?

旧巷老猫 提交于 2019-12-23 23:10:05
问题 If I have an AFTER UPDATE trigger, will SELECT * FROM inserted and SELECT * FROM deleted give me back their records in the same order? I.e. lets say I was able to index into their result sets, will del[5] and ins[5] give me back the matching entries, even if one value of the compound primary key has changed (which would be the reason why an inner join won't work). 回答1: I don't believe there is any guarantee over the ordering of rows within inserted and deleted - just as there is no ordering

ERROR 1442: Can't update table in stored function/trigger because it is already used by statement which invoked this stored function/trigger

China☆狼群 提交于 2019-12-23 22:27:59
问题 I have a table that I want : when the table has been updated, 2 fields of that (title and description) change and take value from another table This is my trigger: drop trigger trigger_trade_request ; CREATE TRIGGER trigger_trade_request AFTER UPDATE ON `trade_request` FOR EACH ROW BEGIN IF NEW.title = null THEN UPDATE `trade_request_type`,`trade_request` SET NEW.title = `trade_request_type`.title , NEW.description = `trade_request_type`.description WHERE `trade_request_type`.id = NEW.trade

Sql Trigger - which table does it belong to?

只愿长相守 提交于 2019-12-23 21:44:09
问题 Is there a way within a Sql Server 2005 Trigger to get the name and schema of the table that the trigger is attached to during execution? 回答1: SELECT OBJECT_NAME(parent_id) AS [Table], OBJECT_NAME(object_id) AS TriggerName FROM sys.triggers WHERE object_id = @@PROCID Then you can also use OBJECTPROPERTY to get extra info, such as after/before, delete/insert/update, first/last etc 回答2: This is a dirty way to know it SELECT o.name FROM sysobjects t JOIN sysobjects o ON t.parent_obj = o.id WHERE

How to use COMMIT in Procedure called by trigger

狂风中的少年 提交于 2019-12-23 21:39:08
问题 I have the below trigger(mytrg) which calls a procedure(myproc) that will update table2 if any insert in table1. I have "COMMIT" statement in the procedure after the data is updated in table2. But when there is an insert in table1, i get the below error. Error report: SQL Error: ORA-04092: cannot COMMIT in a trigger ORA-06512: at "myschema.myproc", line 63 ORA-06512: at "myschema.mytrg", line 2 ORA-04088: error during execution of trigger 'myschema.mytrg' 04092. 00000 - "cannot %s in a

How to prevent an Insert Trigger from being fired when no row is inserted?

守給你的承諾、 提交于 2019-12-23 20:17:06
问题 I have a TABLE1. On this table I created a trigger : AFTER INSERT OR UPDATE OR DELETE Now, if I do an insert which doesn't insert anything, the trigger will still be fired : insert into TABLE1 select * from TABLE1 where 1=0; This query will insert NO ROWS but yet the trigger is still fired. Is there a way to avoid this ? Is this normal behavior? 回答1: Yes, it is normal behaviour. It can be avoided, though doing so requires having 3 triggers: A BEFORE trigger to set a package boolean variable