Back to Papers and Articles | |||||||||||||||||||||||||||||||||||
PostgreSQL - Recursive table returning functions Copyright 2008 Paragon Corporation ( March 16, 2008) |
|||||||||||||||||||||||||||||||||||
A lot of people have asked how you return a table of results in PostgreSQL. In this exercise, we will be using the same data as we did in Using PostgreSQL User-Defined functions to solve the Tree Problem except instead of returning a result that is a string, we will be returning a table. Note this version also assumes PostgreSQL 8 and above so will be using the new standard of $ quoting.
Below is what the structure of your table looks like. si_id int, si_parentid int, si_item. In your table are the following entries
Now everyone at work is asked to throw all their paper in the recycle bin for recycling. With recycling, we are told we will save trees and have plentiful amounts of paper. John loves his paper and doesn't want it to be recycled. He surely doesn't want his beautiful paper to get into someone else's hands. So what he does is wrap his paper in styrofoam and throws it in the recycle bin. He thinks (Hee hee - that'll teach them to ask me to give up my paper). Little does John know that there iare other Johns and Janes in the halls thinking the same thing. The function that will return the parental tree of the paper as a table is listed below .
To figure out what paper John will ask for
SELECT cp_getitemfullname(8) As thename
This returns
Paper->Non-Recycled->Scraps
| |||||||||||||||||||||||||||||||||||
Back to Papers and Articles | |||||||||||||||||||||||||||||||||||
|