database-trigger

How can i create duplicate records based the value in another table

笑着哭i 提交于 2021-01-27 12:43:51
问题 I have two tables in my database, Work_Order table which is the source table where work order information's stored i also have Work_Schedule table which contains work schedules which tell peoples in the production floor what to build, when and how much to build. Work_Order Table looks like Work order ItemCode Size Qty Qty_per_HR 41051 600111 14L-16.1 55 10 I want duplicate the above work order line in work order table above based on the Qty per hour and automatically create a work scheduler

How can i create duplicate records based the value in another table

人走茶凉 提交于 2021-01-27 12:39:33
问题 I have two tables in my database, Work_Order table which is the source table where work order information's stored i also have Work_Schedule table which contains work schedules which tell peoples in the production floor what to build, when and how much to build. Work_Order Table looks like Work order ItemCode Size Qty Qty_per_HR 41051 600111 14L-16.1 55 10 I want duplicate the above work order line in work order table above based on the Qty per hour and automatically create a work scheduler

Use a Postgres trigger to record the JSON of only the modified fields

我只是一个虾纸丫 提交于 2020-12-15 07:08:40
问题 Is there a way to get the JSON of the only modified fields? Now I use the following trigger but the entire line is printed in the changelog. Example tables: TABLE tbl_changelog ( tbl TEXT, op TEXT, new JSON, old JSON ); TABLE tbl_items ( f1 TEXT, f2 TEXT ); Trigger: CREATE OR REPLACE FUNCTION changelog_procedure() RETURNS trigger AS $$ BEGIN INSERT INTO tbl_changelog(tbl, op, new, old) VALUES (TG_TABLE_NAME, TG_OP, row_to_json(NEW), row_to_json(OLD)); RETURN NULL; END; $$ LANGUAGE plpgsql

My $or selector in a database trigger match expression doesn't work at the second level of nesting when configuring a database trigger

蹲街弑〆低调 提交于 2020-08-10 19:22:47
问题 Update : I use "$match expression" to describe this but I don't actually use the $match operator. According to the docs, the selector should conform with $match's syntax, though the $match keyword is apparently not necessary in the actual expression. Update 2 : In the actual collection, outerField represents message , fieldA represents fansNo , and fieldB represents sharedNo . So outerField.fieldA represents message.fansNo and outerField.fieldB represents message.sharedNo . This is a

My $or selector in a database trigger match expression doesn't work at the second level of nesting when configuring a database trigger

限于喜欢 提交于 2020-08-10 19:22:32
问题 Update : I use "$match expression" to describe this but I don't actually use the $match operator. According to the docs, the selector should conform with $match's syntax, though the $match keyword is apparently not necessary in the actual expression. Update 2 : In the actual collection, outerField represents message , fieldA represents fansNo , and fieldB represents sharedNo . So outerField.fieldA represents message.fansNo and outerField.fieldB represents message.sharedNo . This is a

Below is the psql code in which I am having syntax error. I am trying to create a trigger function on my test_route database

China☆狼群 提交于 2020-07-03 13:26:42
问题 CREATE OR REPLACE FUNCTION nearest_segment_insert() RETURNS trigger AS DECLARE id_temp integer; $BODY$ BEGIN IF OLD.id = NULL THEN select test_route.id into id_temp,ST_Distance(test_route.the_geom,NEW.the_geom) FROM test_route, ORDER BY 2 ASC LIMIT 1; UPDATE SET p.edges_id = r.id, p.the_geom = r.the_geom, p.dist_val = r.distance, r.distance = -1 FROM test_route r, road_block p, WHERE id_temp = r.id ; END IF; RETURN NEW; END; $BODY$ I am getting error "syntax error at or near "BEGIN". 回答1: The