<div dir="ltr">I am trying to find all zip codes withing a given range of current zip code. For example, User is at zip code 95076 and want to know all zip codes within a 30 mile range. This will always be a short distance, nothing over 50 miles. The source zip code is any place in the USA.  My input table has a latitude field, a longitude field and a POINT field for each zip code. <div>I want to supply in input in meters, not degrees. I do NOT want to cast to <i>geography</i> because this prevents the index from being used. </div><div>Here is a <b><i>working query</i></b> that uses the index, but ST_DWithin  is not understanding ".05" as meters:</div><div><br></div><div><br></div><div><div><font face="courier new, monospace" color="#351c75">lcd1_dev=>   select t2.city, t2.postalcode, ST_Distance(t1.geo_position,<wbr>t2.geo_position)</font></div><div><font face="courier new, monospace" color="#351c75">lcd1_dev->   from      tpostalcoordinate t1</font></div><div><font face="courier new, monospace" color="#351c75">lcd1_dev->   left join tpostalcoordinate t2 on ST_DWithin(t1.<b>geo_position</b>,t2.<wbr><b>geo_position</b> , .05)</font></div><div><font face="courier new, monospace" color="#351c75">lcd1_dev->   where t1.postalcode = '94404'and t1.countrycode2tcountry = 'US' and t2.countrycode2tcountry= 'US';</font></div><div><font face="courier new, monospace">     city     | postalcode |     st_distance</font></div><div><font face="courier new, monospace">--------------+------------+--<wbr>-------------------</font></div><div><font face="courier new, monospace"> Redwood City | 94065      |  0.0273766323714193</font></div><div><font face="courier new, monospace"> San Mateo    | 94408      | 0.00504738546179631</font></div><div><font face="courier new, monospace"> Belmont      | 94002      |  0.0440065904155286</font></div><div><font face="courier new, monospace"> San Mateo    | 94404      |                   0</font></div><div><font face="courier new, monospace"> San Mateo    | 94403      |  0.0370314731005901</font></div><div><font face="courier new, monospace"> San Mateo    | 94407      |  0.0416118372581607</font></div><div><span style="font-family: 'courier new', monospace;"><br></span></div><div><span style="font-family: 'courier new', monospace;"><b>This shows that I am using SRID 4896</b></span></div></div><div><font face="courier new, monospace">lcd1_dev=> select * from geometry_columns where f_table_name = 'tpostalcoordinate';</font></div><div><font face="courier new, monospace"> f_table_catalog | f_table_schema |   f_table_name    | f_geometry_column | coord_dimension | srid | type</font></div><div><font face="courier new, monospace">-----------------+------------<wbr>----+-------------------+-----<wbr>--------------+---------------<wbr>--+------+-------</font></div><div><font face="courier new, monospace"> lcd1_dev        | qsn_app        | tpostalcoordinate | geo_position      |               2 | 4896 | POINT </font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><b>4896 is UNIT "metre" as show here:</b></font></div><div><div><span style="line-height: 22.8571px;"><font face="Ubuntu Mono, Menlo, Monaco, Consolas, Courier New, monospace" style="color: rgb(255, 255, 255); font-size: 16px;"> </font><font face="courier new, monospace" size="1" color="#000000">4896 | EPSG      |      4896 | GEOCCS["ITRF2005",DATUM["<wbr>International_Terrestrial_<wbr>Reference_Frame_2005",<wbr>SPHEROID["GRS 1980",6378137,298.257222101,<wbr>AUTHORIT</font></span></div><div><font face="courier new, monospace" size="1"><span style="line-height: 22.8571px;"><font color="#000000">Y["EPSG","7019"]],AUTHORITY["<wbr>EPSG","6896"]],PRIMEM["<wbr>Greenwich",0,AUTHORITY["EPSG",<wbr>"8901"]],</font><font color="#cc0000" style="background-color: rgb(255, 255, 0);">UNIT["metre"</font><font color="#000000">,1,<wbr>AUTHORITY["EPSG","9001"]],<wbr>AXIS["Geocentric X",OTH</font></span></font></div><div><span style="line-height: 22.8571px;"><font face="courier new, monospace" size="1" color="#000000">ER],AXIS["Geocentric Y",OTHER],AXIS["Geocentric Z",NORTH],AUTHORITY["EPSG","<wbr>4896"]] | +proj=geocent +ellps=GRS80 +units=m +no_de</font></span></div><div><span style="line-height: 22.8571px;"><font face="courier new, monospace" size="1" color="#000000"><br></font></span></div><div><span style="line-height: 22.8571px;"><font face="courier new, monospace" color="#000000" size="2"><b>The following (from EXPLAIN) proves that the index is being used in the working query shown above:<span style="background-color: rgb(255, 255, 255);"><br></span></b></font></span><span style="color: rgb(11, 83, 148); font-family: 'courier new', monospace; font-size: x-small; line-height: 22.8571px; background-color: rgb(255, 217, 102);">   ->  Index Scan using tpostalcoordinate_pk on tpostalcoordinate t1  (cost=0.42..8.45 rows=1 width=32)</span></div><div><font face="courier new, monospace" size="1"><span style="line-height: 22.8571px;"><div style="color: rgb(0, 0, 0);"><br></div></span></font></div><div><span style="line-height: 22.8571px;"><font face="Ubuntu Mono, Menlo, Monaco, Consolas, Courier New, monospace" color="#000000" style="font-size: 16px;">What do I need to do to get this in meters without losing my index access?</font></span></div></div><div><span style="line-height: 22.8571px;"><font face="Ubuntu Mono, Menlo, Monaco, Consolas, Courier New, monospace" color="#000000" style="font-size: 16px;"><br></font></span></div><div><span style="line-height: 22.8571px;"><font face="Ubuntu Mono, Menlo, Monaco, Consolas, Courier New, monospace" color="#000000" style="font-size: 16px;">TIA,</font></span></div><div><span style="line-height: 22.8571px;"><font face="Ubuntu Mono, Menlo, Monaco, Consolas, Courier New, monospace" color="#000000" style="font-size: 16px;">Mike</font></span></div></div>