Re: query performance

From: PT <wmoran(at)potentialtech(dot)com>
To: hmidi slim <hmidi(dot)slim2(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: query performance
Date: 2018-02-20 21:36:54
Message-ID: 20180220163654.573904ced0aee564c6467112@potentialtech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 18 Feb 2018 00:35:18 +0100
hmidi slim <hmidi(dot)slim2(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message yeli 2018-02-20 22:18:05 Re: Crear Una FUNTION usando ROW_NUMBER
Previous Message Hellmuth Vargas 2018-02-20 21:28:46 Re: Crear Una FUNTION usando ROW_NUMBER