Author | Message |
---|---|
jcalilu
Posts: 20
|
Posted 10:52 Apr 30, 2016 |
1. Is there a preferred way to process queries (Using the for loop vs a cursor)? Since they both do the same thing. 2. Is a bound cursor the same as an initialized cursor? If not, what is the difference between bound and unbound. I'm not sure I have the right idea about bound and unbound cursor. Thanks in advance. |
cysun
Posts: 2935
|
Posted 11:13 Apr 30, 2016 |
1. Use query for-loop. It's syntactically simpler, more readable, and it automatically opens and closes a cursor so there's less chance of human error (e.g. forgetting to close a cursor). 2. Bound means a cursor is associated with a query. For example, in the following declarations, c1 is unbound while c2 is bound: c1 refcursor; c2 cursor for select * from students; Opened means the query associated with a cursor is executed and the cursor is ready to be used. For example, the following statement opens c2:
And the following statement binds and opens c1:
I think PostgreSQL does not use the term "initialized". If other DBMS uses the term, my guess is that is means "opened" rather than "bound". |