Re: Stored Procedure Assistance

From: Michael Pohl <pgsql(at)newtopia(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Stored Procedure Assistance
Date: 2003-07-08 17:25:30
Message-ID: Pine.LNX.4.44.0307081323510.28045-100000@server1.techplant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 8 Jul 2003, Bradley J. Bartram wrote:

> The first query is simple:
>
> SELECT a FROM table_a WHERE column_a = b
>
> This will return a single row. The next query takes that derived value
and
> does a simliar select that returns multiple rows.
>
> 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?

Are you sure you need plpgsql to get from point a to point d? It looks
like this could be a single query:

select d from table_c where column_c in
(select c from table_a, table_b where
table_a.column_a = b and
table_b.column_b = table_a.a)

michael

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2003-07-08 17:27:12 Re: Stored Procedure Assistance
Previous Message Chris Travers 2003-07-08 17:25:02 Re: Benchmarking