From: PT <wmoran@potentialtech.com>
To: hmidi slim <hmidi.slim2@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: query performance
Date: Tue, 20 Feb 2018 16:36:54 -0500
Message-ID: <20180220163654.573904ced0aee564c6467112@potentialtech.com> (raw)
In-Reply-To: <CAMsqVxvaucQ6p7f5RSE34uMwY0NQ=u4AaoabYTWeU57MWKxyzQ@mail.gmail.com>
References: <CAMsqVxvaucQ6p7f5RSE34uMwY0NQ=u4AaoabYTWeU57MWKxyzQ@mail.gmail.com>
On Sun, 18 Feb 2018 00:35:18 +0100
hmidi slim <hmidi.slim2@gmail.com> wrote:
> Hi,
> I have two tables: establishment which contains these columns: id, name,
> longitude, latitude, geom (Geometric column)
> Product contains: id, name, establishment_id
> First of all I want to select the establishment within a radius.
> I run this query:
> select e.name, e1.name
> from establishment as e, establishment as e1
> where e.id <> e1.id
> and e1.id = 1
> and ST_DWithin(geom, ST_MakePoint(e1.longitude, e1.latitude)::geography,
> 1000)
>
> The result of this query returns all the establishment within a radius 1KM
> from from a given establishment which has an id = 1.
>
> After that I want to get the product's name of each establishment from the
> query's result.
>
> Is there an other optimized solution to make a query such this:
> select * from (
> select e.name, e1.name, e.id
> from establishment as e, establishment as e1
> where e.id <> e1.id
> and e1.id = 1
> and ST_DWithin(geom, ST_MakePoint(e1.longitude, e1.latitude)::geography,
> 1000)) as tmp inner join product as p on p.establishment_id = tmp.id
Did you not see my earlier response?
--
Bill Moran
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: wmoran@potentialtech.com, hmidi.slim2@gmail.com
Subject: Re: query performance
In-Reply-To: <20180220163654.573904ced0aee564c6467112@potentialtech.com>
References: <CAMsqVxvaucQ6p7f5RSE34uMwY0NQ=u4AaoabYTWeU57MWKxyzQ@mail.gmail.com> <20180220163654.573904ced0aee564c6467112@potentialtech.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox