Re: Stored Procedure Assistance
| От | Alvaro Herrera |
|---|---|
| Тема | Re: Stored Procedure Assistance |
| Дата | |
| Msg-id | 20030708171545.GB12195@dcc.uchile.cl обсуждение исходный текст |
| Ответ на | Stored Procedure Assistance ("Bradley J. Bartram" <bbartram@dyrectmedia.com>) |
| Список | pgsql-general |
On Tue, Jul 08, 2003 at 12:55:00PM -0400, Bradley J. Bartram wrote:
> SELECT c FROM table_b WHERE column_b = a
>
> The next query has some logic in php that constructs it. Basically if c > 0
> than the results of query 2 are setup as ORs in the WHERE clause.
>
> SELECT d FROM table_c WHERE column_c = c1 OR column_c = c2, etc.
>
> The first two queries are not a problem, but how can I take the array of
> results from query 2 and put them into query 3?
Huh... why don't you do a
SELECT d FROM table_c WHERE column_c IN (SELECT c FROM table_b WHERE column_b = a)
(or convert to EXISTS for performance)
Another approach could be to build a string, say
string = ''SELECT d FROM table_c WHERE '';
FOR blah IN SELECT-values-for-c LOOP
string = string || ''OR column_c = '' || blah
END LOOP;
EXECUTE string;
(adjust as needed, exclude the OR in the first iteration, etc)
--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Los romanticos son seres que mueren de deseos de vida"
В списке pgsql-general по дате отправления: