michal123
michal123

Reputation: 1

trigger function in postgresql

I want to write a trigger that operated only after all the data I need was inserted. if for example i'm waiting for 10 parameters, I want to operate the trigger after I get all the 10 parameters. can I do it in postgresql? how can I know that all the data that I need already inserted?

Thanx

Upvotes: 0

Views: 38

Answers (1)

Craig Ringer
Craig Ringer

Reputation: 324315

In the general case, you can't. The trigger will run on every insert. It needs to look and see whether all the info it wants is there and do nothing if it isn't yet. That's because PostgreSQL has no idea what "all the data" means.

If you can find a way to express that condition in a useful way, like a trigger WHEN clause, such that you can write it as a predicate you might be able to do it. You haven't provided anywhere near enough information to guess.

You may also want to look into deferred constraint triggers. See the documentation.

Upvotes: 1

Related Questions