Re: Constructing a SELECT statement in pl/pgsql - Mailing list pgsql-general

From Richard Huxton
Subject Re: Constructing a SELECT statement in pl/pgsql
Date
Msg-id 464B87F8.30804@archonet.com
Whole thread Raw
In response to Constructing a SELECT statement in pl/pgsql  (Robert Fitzpatrick <lists@webtent.net>)
List 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

pgsql-general by date:

Previous
From: Robert Fitzpatrick
Date:
Subject: Constructing a SELECT statement in pl/pgsql
Next
From: Brian Wipf
Date:
Subject: Re: Performance issues of one vs. two split tables.