Re: [Hampshire] SQL SELECT query.

Top Page
Author: Hugo Mills
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] SQL SELECT query.

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x57840100.hantslug.org.uk.12276': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Sun Dec 6 19:59:10 2009 GMT
gpg: using DSA key 20ACB3BE515C238D
gpg: Can't check signature: No public key
On Sun, Dec 06, 2009 at 07:32:25PM +0000, Philip Stubbs wrote:
> Hi,
>
> I have been playing with mapnik to create some maps. It has been fun,
> but I am a bit lacking in Postgres SQL. Can anybody help me to adjust
> the following SELECT statement so that it will return a result set
> that consists of only one of each distinct 'name'?


In brief, no. What you're asking for, on the face of it, doesn't
really make sense in SQL.

>  SELECT way,highway,aeroway,name,ref,char_length(ref) AS length,
> ST_Length(way) AS road_len,
>        CASE WHEN bridge IN ('yes','true','1') THEN 'yes'::text ELSE
> bridge END AS bridge


You've selected a whole bunch of fields here. If there's, say, two
records with the same name but different "way" values, what do you
want it to do? Pick an arbitrary record where the name matches?

>        FROM planet_osm_line
>        WHERE waterway IS NULL
>          AND leisure IS NULL
>          AND landuse IS NULL
>          AND (name IS NOT NULL OR ref IS NOT NULL)
>          ORDER BY road_len DESC


If you simply want a list of unique names, then:

SELECT name FROM planet_osm_line WHERE [...] GROUP BY NAME;

It might help us if you explain what you want to do with the data
from this query.

Hugo.

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
          --- ...  one ping(1) to rule them all, and in the ---          
                         darkness bind(2) them.