How to write a Cursor for PostgreSQL. Learn how to Open, Move, Fetch, Close., and Update/Delete DB.

Published: 05 September 2022
on channel: Software Nuggets
3,971
66

How to write a Cursor that loops over a result set, and allow the program to evaluate each row.

table of contents:
00:00 begin
00:12 - build a table and insert data
00:44 - build a basic cursor
06:42 - learn how to fetch
09:42 - learn how to loop
11:54 - learn how to loop in reverse
13:47 - learn how to update base table (and how to use random() function)
17:44 - learn how to delete from base table
21:25 - closing message from software nuggets


Access a cursor in PL/pgSQL goes through cursor variables, which are always of the special data type refcursor.
How to declare a rowset object using the database.tablename%ROWTYPE
How to open and close a cursor
How to use the cursor move method to reposition the current pointer
How to the the curosr fetch method using the directions: first, last, prior, next and relative
How to use the special variable "found" to exit a loop

Use the built-in RANDOM function and LIMIT the number of Records to be used in a Cursor.

How to use raise notice to print a response to the Messages tab.

#softwareNuggets, #postgresql


On this page of the site you can watch the video online How to write a Cursor for PostgreSQL. Learn how to Open, Move, Fetch, Close., and Update/Delete DB. with a duration of hours minute second in good quality, which was uploaded by the user Software Nuggets 05 September 2022, share the link with friends and acquaintances, this video has already been watched 3,971 times on youtube and it was liked by 66 viewers. Enjoy your viewing!