advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   TIP BANK
Browse DevX
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
 

PostgreSQL Version 8's Transaction Savepoints Can Save Your Data

While transactions are nice, PostgreSQL's current all-or-nothing transaction mechanism leaves much to be desired when an error occurs within the transaction code. Fortunately, the upcoming PostgreSQL version 8 addresses that problem by adding "savepoints," letting you roll back only part of a transaction and recover from errors gracefully. 


advertisement
ne much-lauded feature of PostgreSQL is transactions. Transactions in a database help prevent accidental data loss or misrepresentation.

For example, let's say you want to delete records from a table. In PostgreSQL the command is:
 template1=# DELETE FROM foo; 
However, the above command will delete all of the records in the table. This is probably not what you want, and—unless you were using transactions—the only way to get the data back would be from a backup. Using transactions, getting the data back is simple. The command sequence would be:
BEGIN;
DELETE FROM foo;
DELETE 50

It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com.
Already a member?



advertisement