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 9024883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:08:09+00:00 2026-06-16T06:08:09+00:00

I have a table in postgresql 9.2 that stores the latitude and longitude of

  • 0

I have a table in postgresql 9.2 that stores the latitude and longitude of locations as integer values.

I intend to do something like when a user searches for a location, he also gets information on other locations that are within a 7 mile radius of that searched location.

How do i use postGIS for this since i am new to it. Any idea.?

  • 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-16T06:08:10+00:00Added an answer on June 16, 2026 at 6:08 am

    You’ll actually want to store the latitude and longitude as a point.

    CREATE TABLE postal_codes
    (
      zip character varying(7) NOT NULL,
      state character(2) NOT NULL,
      city character varying(50) NOT NULL,
      geoloc geography(Point,4326) NOT NULL
    );
    INSERT INTO postal_codes
    VALUES (
        '35004', 'AL', 'Moody',
        ST_GeographyFromText('SRID=4326;POINT(-86.50249 33.606379)') -- lon lat
    );
    

    You can then get all points within a certain distance using STDWithin.

    SELECT geoloc
    FROM postal_codes
    WHERE ST_DWithin(
        geoloc,                            -- The current point being evaluated
        'thegeolocyoustoredawaysomewhere', -- the location of the person
                                           -- you're giving info to
        7 * 1.6 * 1000                     -- Miles to meters
    );
    

    Or:

    SELECT geoloc
    FROM postal_codes
    WHERE ST_DWithin(
        geoloc,
        (
            SELECT geoloc
            FROM postal_codes
            WHERE zip = '12345'
        ),
        7 * 1.6 * 1000
    );
    

    To boost performance a bit for other kinds of queries (not any seen here), use a GiST index:

    CREATE INDEX geoloc_idx
    ON postal_codes
    USING gist (geoloc);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that looks something like this: CREATE TABLE student_results(id integer, name
I have one table that stores values with a point in time: CREATE TABLE
I have a table in my postgresql 8.4 database like this: id(serial), event_type_id(id, foreign
I have 2 integer fields in a table user: leg_count and leg_length. The first
I have a table named visiting that looks like this: id | visitor_id |
I have a table that stores two foreign keys, implementing a n:m relationship. One
I have a table representing values of source file metrics across project revisions, like
That title is presumably awfully worded. I have some PostgreSQL tables. There is a
Background In a PostgreSQL 9.0 database, there are various tables that have many-to-many relationships.
is is possible in postgres to have a trigger on CREATE TABLE that will

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.