| From: | Richard Huxton <dev(at)archonet(dot)com> |
|---|---|
| To: | Robert Fitzpatrick <lists(at)webtent(dot)net> |
| Cc: | PostgreSQL <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Constructing a SELECT statement in pl/pgsql |
| Date: | 2007-05-16 22:38:48 |
| Message-ID: | 464B87F8.30804@archonet.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Robert Fitzpatrick wrote:
> I guess my question is how to replace the following...
>
> FOR searchresults IN SELECT * FROM my_view WHERE <snip> LOOP
>
> With something like this...
>
> FOR searchresults IN SELECT DISTINCT clientname FROM my_view WHERE <snip> LOOP
Build the query as text and use EXECUTE (see manuals for details).
You'll also find quote_ident() and quote_literal() useful - again see
manuals.
You'll need to think through the type implications of picking columns
based on supplied parameters - how do you cope with selecting an integer
this time and a text column next time?
--
Richard Huxton
Archonet Ltd
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Glen Parker | 2007-05-16 22:40:27 | Vacuum non-clustered tables only |
| Previous Message | Brian Wipf | 2007-05-16 22:15:55 | Re: Performance issues of one vs. two split tables. |