Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Triggers that Create Tables

Status
Not open for further replies.

JWHardcastle

Programmer
Feb 17, 2003
3
US
I have a web application on a Win box that accesses a Postgres DB on a *nix box using ODBC. I also have a trigger that fires every time I update,insert, or delete on a specific table. The trigger creates a temporary table and then drops it at the end. I can only update the table once before it complains "relation XXXXX not found." I've traced this back to not "committing" my transactions, but when I wrap my updates in "BEGIN;" and "COMMIT;" - it still doesn't work. I've tried using EMS PostgreSQL Manager, and even there if I do my own transaction, it fails, but if I use the "COMMIT" button, it works. Any ideas?
 
Every triggered function is implicitly run inside a transaction. Unfortunately, at present PostgreSQL is not capable of nesting transactions inside other transactions, so adding "BEGIN" and "COMMIT" inside your function will not help.

I'm not familiar with EMS PostgreSQL Manager, so I have no idea exactly what you are talking about there.

I would have to know more about the structure of the temporary table, to understand why there is a problem with multiple updates. Generally, there is no problem with multiple updates inside a single transaction.

More than likely, though, there is another way to handle your problem. In fact, I personally doubt whether it is even necessary to create a temporary table. Any PostgreSQL function is capable of maintaining variables, even arrays, during the transaction, so why not take advantage of that, rather than going to the trouble of creating, then releasing a temp table?

Also, you might consider using a RULE, rather than a trigger to handle your problem. RULEs are simply rewritten SQL statements, but they can contain multiple SQL statements, which are the internal result of the single external SQL query. -------------------------------------------

My PostgreSQL FAQ --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top