# Finding Nearby Cities with PostgreSQL KNN Queries

DevFeed: [Finding Nearby Cities with PostgreSQL KNN Queries](<https://devfeed.tech/articles/nearest-big-city-34503.md>)

Original publisher: [Read original article](<https://tapoueh.org/blog/2013/05/nearest-big-city/>)

Author: Dimitri Fontaine PostgreSQL Major Contributor; Author

Published: 2013-05-02T09:34:00Z

Content type: tutorial

Language: en

Sources: [Dimitri Fontaine](<https://devfeed.tech/sources/dimitri-fontaine.md>)

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Query (disambiguation)](<https://devfeed.tech/topics/query.md>), [CSV](<https://devfeed.tech/topics/csv.md>), [data](<https://devfeed.tech/topics/data.md>), [import](<https://devfeed.tech/topics/import.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [csv](<https://devfeed.tech/tags/csv.md>), [data](<https://devfeed.tech/tags/data.md>), [import](<https://devfeed.tech/tags/import.md>), [indexes](<https://devfeed.tech/tags/indexes.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [query](<https://devfeed.tech/tags/query.md>)

## AI overview

This tutorial uses CSV data about cities, including coordinates and population, to find nearby towns and associate towns worldwide with their nearest large city using PostgreSQL queries and KNN indexes.

## Source excerpt

In this article, we want to find the town with the greatest number of inhabitants near a given location. A very localized example We first need to find and import some data, and I found at the following place a CSV listing of french cities with coordinates and population and some numbers of interest for the exercise here. To import the data set, we first need a table, then a COPY command: