简体   繁体   中英

Will an AFTER trigger in Postgres block an insert/update?

If I set up an AFTER trigger in PostgreSQL to fire after an insert/update, will the calling software have to wait for the trigger to finish before returning control to the calling software? Or will the trigger run on its own behind the scenes?

Yes, because it's executed within the same transaction. If the trigger fails, the insert/update will also fail. Just do a test executing a query that will fail (SELECT a table that does not exist) and you can see how things work and how your application will behave.

CREATE OR REPLACE FUNCTION foo() RETURNS TRIGGER
AS
$$
BEGIN
  EXECUTE 'SELECT fail';
END;
$$
LANGUAGE plpgsql;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM