title: Pass In "WHERE" parameters to PostgreSQL View?
body: <p>I have a rather complicated query on my PostgreSQL database spanning 4 tables via a series of nested subqueries. However, despite the slightly tricky looking appearance and setup, ultimately it will return two columns (from the same table, if that helps the situation) based on that matching of two external parameters (two strings need to match with fields in different tables). I'm fairly new to database design in PostgreSQL, so I know that this seemingly magical thing called Views exist, and that seems like it could help me here, but perhaps not.</p>
  
  <p>Is there some way I can move my complex query inside a view and somehow just pass it the two values I need to match? That would greatly simplify my code on the front-end (by shifting the complexities to the database structure). I can create a view that wraps my static example query, and that works just fine, however that only works for one pair of string values. I need to be able to use it with a variety of different values.</p>
  
  <p>Thus my question is: is it possible to pass parameters into an otherwise static View and have it become "dynamic"? Or perhaps a View is not the right way to approach it. If there's something else that would work better, I'm all ears!</p>
  
  <p>*<em>Edit: *</em> As requested in comments, here's my query as it stands now:</p>
  
  <pre><code>SELECT   param_label, param_graphics_label
    FROM   parameters
   WHERE   param_id IN 
           (SELECT param_id 
              FROM parameter_links
             WHERE region_id = 
                   (SELECT region_id
                      FROM regions
                     WHERE region_label = '%PARAMETER 1%' AND model_id =
                           (SELECT model_id FROM models WHERE model_label = '%PARAMETER 2%')
                   )
           ) AND active = 'TRUE'
  ORDER BY param_graphics_label;
  </code></pre>
  
  <p>Parameters are set off by percent symbols above.</p>