RE: [SQL] Returning multiple rows in functions - Mailing list pgsql-sql

From Kief Morris
Subject RE: [SQL] Returning multiple rows in functions
Date
Msg-id 30C64922AF42D311A96D00A0C91D0B107EB551@mailpost.syzygy.net
Whole thread Raw
List pgsql-sql
> > ... but it only returns the first matching row. Is there
> > a way to return all the matching rows?
> 
> No. Perhaps making a view would fit your application.

Looking over the docs for views, it doesn't seem like it
will work - I would need to create a new view for each
request, since the WHERE clause of the query changes 
depending on the user.

My query is actually a bit more complex than the example
I provided, I'm trying to do the following:

SELECT id FROM mytable WHERE
( value_id = 1  AND value < $1 + 1 AND value > $1 - 1 ) OR
( value_id = 2  AND value < $6 + 1 AND value > $6 - 1 ) OR
( value_id = 3  AND value < $7 + 1 AND value > $7 - 1 );

... and actually, I need to have about 10 of those clauses
in the WHERE clause of the statement. This is insanely
inefficient, there's got to be a smarter way to do this. 



pgsql-sql by date:

Previous
From: Karl Denninger
Date:
Subject: Re: [SQL] index file's growing big
Next
From: "Ross J. Reedstrom"
Date:
Subject: Re: [SQL] index file's growing big