Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PostgreSQL 11 Administration Cookbook

You're reading from  PostgreSQL 11 Administration Cookbook

Product type Book
Published in May 2019
Publisher Packt
ISBN-13 9781789537581
Pages 600 pages
Edition 1st Edition
Languages
Concepts
Authors (3):
Simon Riggs Simon Riggs
Profile icon Simon Riggs
Gianni Ciolli Gianni Ciolli
Profile icon Gianni Ciolli
Sudheer Kumar Meesala Sudheer Kumar Meesala
Profile icon Sudheer Kumar Meesala
View More author details
Toc

Table of Contents (19) Chapters close

Title Page
Copyright and Credits
About Packt
Contributors
Preface
1. First Steps 2. Exploring the Database 3. Configuration 4. Server Control 5. Tables and Data 6. Security 7. Database Administration 8. Monitoring and Diagnosis 9. Regular Maintenance 10. Performance and Concurrency 11. Backup and Recovery 12. Replication and Upgrades 1. Other Books You May Enjoy Index

Making bulk data changes using server-side procedures with transactions


In some cases, you’ll need to make bulk changes to your data. In many cases, you need to scroll through the data making changes according to a complex set of rules. You have a few choices in that case:

  • Write a single SQL statement that can do everything
  • Open a cursor and read the rows out, then make changes with a client-side program
  • Write a procedure that uses a cursor to read the rows and make changes using server-side SQL

Writing a single SQL statement that does everything is sometimes possible, but, if you need to do more than just UPDATE then it becomes difficult very quickly. The main difficulty is that the SQL statement isn't restartable, so, if you need to interrupt it then you lose all of your work.

Reading all the rows back to a client-side program can be very slow – if you need to write this kind of program, it is better to do it all on the database server.

 

 

How to do it…

We're going to write a Procedure in PL/pgSQL...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime