title: How do i get a list of all the latitudes and longitudes from a database within a specific area?
body: <p>I have a table in a Postgres DB containing places and their corresponding latitude and longitude values. </p>
  
  <pre><code>Places (id, name, lat, lng)  # primary-key(id)
  </code></pre>
  
  <p>I will get an input of a pair of latitudes and longitudes forming a rectangle.</p>
  
  <pre><code>{
    "long_ne": 12.34, 
    "lat_ne": 34.45, 
    "long_sw": 15.34, 
    "lat_sw": 35.56
  }
  </code></pre>
  
  <p>I want to get all the rows that <em>fall</em> inside the rectangle.</p>
  
  <p>The rows can't be sorted based on their lat-lng values as that will cause trouble while inserting new values.</p>
  
  <p>What would be the best way to go about solving this to optimize queries to get the result?</p>
  
  <p>I can obviously do it using the <code>WHERE</code> clause, but would it be the ost optimized solution? There would be a massive number of rows in the table and is there a way this query can be optimized to speed up the result?</p>