From: Adrian Klaver <adrian.klaver@gmail.com>
To: Stefan Keller <sfkeller@gmail.com>
Cc: pgsql-general List <pgsql-general@postgresql.org>
Cc: PostGIS Users Discussion <postgis-users@postgis.refractions.net>
Subject: Re: Query with LIMIT but as random result set?
Date: Tue, 08 Jan 2013 07:27:21 -0800
Message-ID: <50EC3AD9.1030902@gmail.com> (raw)
In-Reply-To: <CAFcOn29dNnQVAbqvTKoy3iwUK7sZOosvG0gRzPHW5DxA0Z9W-A@mail.gmail.com>
References: <CAFcOn29dNnQVAbqvTKoy3iwUK7sZOosvG0gRzPHW5DxA0Z9W-A@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>
On 01/08/2013 07:20 AM, Stefan Keller wrote:
> Hi
>
> I have a query like this
>
> SELECT ST_AsText(way) geom, name AS label
> FROM osm_point
> LIMIT 10;
>
> When I repeatedly do this, the result set will be always the same.
> I have observed this only empirically and I know that the ordering of
> the result set is undefined without ORDER BY.
> There are two indexes involved, one geospatial for way and one for name.
>
> My question is: Does someone have an idea on how to randomize the
> result set on every consecutive query?
> And as an option the (limited) resultset should be spatially
> distributed (not clustered).
SELECT ST_AsText(way) geom, name AS label
FROM osm_point ORDER BY random()
LIMIT 10;
>
> Yours, Stefan
>
>
--
Adrian Klaver
adrian.klaver@gmail.com
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
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: adrian.klaver@gmail.com, sfkeller@gmail.com, postgis-users@postgis.refractions.net
Subject: Re: Query with LIMIT but as random result set?
In-Reply-To: <50EC3AD9.1030902@gmail.com>
References: <CAFcOn29dNnQVAbqvTKoy3iwUK7sZOosvG0gRzPHW5DxA0Z9W-A@mail.gmail.com> <50EC3AD9.1030902@gmail.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