Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7755913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:41:04+00:00 2026-06-01T12:41:04+00:00

i have latitude and longitude columns in location table in PostgreSQL database, and I

  • 0

i have latitude and longitude columns in location table in PostgreSQL database,
and I am trying to execute distance query with a PostgreSQL function.

I read this chapter of the manual:

https://www.postgresql.org/docs/current/static/earthdistance.html

but I think I’m missing something there.

How should I do that? Are there more examples available

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:41:06+00:00Added an answer on June 1, 2026 at 12:41 pm

    This module is optional and is not installed in the default PostgreSQL instalatlion. You must install it from the contrib directory.

    You can use the following function to calculate the approximate distance between coordinates (in miles):

     CREATE OR REPLACE FUNCTION distance(lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT) RETURNS FLOAT AS $$
    DECLARE                                                   
        x float = 69.1 * (lat2 - lat1);                           
        y float = 69.1 * (lon2 - lon1) * cos(lat1 / 57.3);        
    BEGIN                                                     
        RETURN sqrt(x * x + y * y);                               
    END  
    $$ LANGUAGE plpgsql;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Group, I have table columns ProductID, latitude,longitude,timestampGMT and looking for a query to count
I have a table with columns latitude and longitude. In most cases the value
I have a table with two columns: latitude and longitude. I want to get
I have a SQLite database in Android with a table that contains longitude, latitude
I have a data table in my SQLite database with information about longitude, latitude
I have a database which has one table, Schools. This table also has latitude
I currently have a database table called civic_zip_code with zip, city, state, latitude, longitude
i have latitude and longitude of a location and i want to find nearby
I have latitude and longitude saved inside a database. I have the bing map
I have a table full of longitude/ latitude pairs in decimal format (e.g., -41.547,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.