views:

85

answers:

1

I'm trying to write a store procedure that can take some input parameters (obviously), run multiple queries against those, taking the output from those and doing calculations, and from those calculations and the original queries, outputting a formatted text string like:

Number of Rows for max(Z) matching condition x and y of total rows matching x (x&y/x*100).

To explain the max(Z) bit, this will be the username field, it won't matter which actual entry is picked, because the where clause will filter the results by user id, is there a saner way to do this?

A: 

For starters break the code up into multiple procedures. Don't create one procedure that does all of these things.

StarShip3000
Reading this document: http://www.postgresql.org/docs/8.3/static/plpgsql.htmlHas clarified how these things work for me, what i was looking for was the PL/pgSQL "SELECT ... INTO ..." syntax. That at text concatentation "||", and some other small things, but thank you both for your suggestions.
fenix