Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Triggers that Create Tables

Triggers that Create Tables

Triggers that Create Tables

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?

RE: Triggers that Create Tables

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 -- http://brainscraps.com/faq/pg_my.html

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close