title: PostgreSQL/PostGIS: Programmatically generate buffer until two rows are returned
body: <p>I have two tables in my PostgreSQL 9.6 database i.e., line and building containing geometry columns. The following query returns the intersection of buffer around street and building geometry (when true in a given distance).</p>
  
  <pre><code>Select
  building.geom as bu_geom
  From
  line
  left join building on
  /* start by 1 meter buffer*/
  st_intersects(ST_Buffer(line.geom, 1), building.geom)
  </code></pre>
  
  <p>There are two building polygons on both sides of line at 11 and 15 meters respectively. I need to modify above query such that buffer should start from 1 meter and continue to increase until two rows (both buildings) and buffer distance are returned. Can somebody suggest me how to do that?</p>