DEV Community

Discussion on: build reactive realtime apps with POSTGRES

Collapse
 
jassenjj profile image
Yasen Velichkov

Hello Tobias,
it's an interesting topic but there are some issues with the code. A trigger function returning NULL cancels the operation that triggered it. Your code only works because you call the function as a procedure in the trigger definition which ignores the return value of the function. (Here there is a misconception if you read old PostgreSQL docs v10 and earlier, when these were indeed called as procedures - just switch between the versions: postgresql.org/docs/13/plpgsql-tri...)

Just for clearing the concepts I would be glad if the function returns the NEW value unless TG_OP = 'DELETE' when only the OLD value is accessible. Then the trigger definition should call it as a function because calling it as a procedure is an undocumented behavior as of PostgreSQL 11 and newer.

Collapse
 
bias profile image
Tobias Nickel

Ohh, yes, my tests where made using a version 9.

Thanks, I will see to do an update. 👍