| From: | Craig Ringer <craig(at)postnewspapers(dot)com(dot)au> | 
|---|---|
| To: | Jasen Betts <jasen(at)xnet(dot)co(dot)nz> | 
| Cc: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking? | 
| Date: | 2009-05-03 05:00:21 | 
| Message-ID: | 49FD24E5.3090509@postnewspapers.com.au | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Jasen Betts wrote:
> That means storing a long list of numbers and doing queries similar to
> the following to get ne next value for the sequence.
> 
> select id from idtable 
>   order by id 
>   limit 1 
>   offset random(0, (select count (*) from idtable)
> 
> a ramdom-looking  1:1 mapping is potentially much more efficient.
You'd probably be better off generating it with something like:
CREATE TABLE shuffled AS (n integer, s integer)
AS SELECT n, NULL FROM generate_series(0, max_value) AS n;
SELECT shuffle(); -- sets `s' for each `n'
... then querying it with:
SELECT s FROM shuffled WHERE n = <value-wanted>;
... but you still have to generate, shuffle, and store a huge collection
of values.
--
Craig Ringer
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Craig Ringer | 2009-05-03 05:13:02 | Re: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking? | 
| Previous Message | Jasen Betts | 2009-05-03 04:41:35 | Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking? |