Re: [GENERAL] Update table with random values from another table

2009-02-16 Thread Brent Wood
I'm not sure if that query will do what you want, but to make it work, one thing you might try, is to pre calculate the random values for each record, then order by those, eg: select trip_code, random() as rand from obs order by rand; works for me, so the following might for you: : UPDA

Re: [GENERAL] Update table with random values from another table

2009-02-12 Thread Sam Mason
On Thu, Feb 12, 2009 at 05:39:49PM +, Rory Campbell-Lange wrote: > On 12/02/09, Rory Campbell-Lange (r...@campbell-lange.net) wrote: > > I realise that for every row in my users table (which has a unique > > integer field) I can update it if I construct a matching id field > > against a random

Re: [GENERAL] Update table with random values from another table

2009-02-12 Thread Rory Campbell-Lange
On 12/02/09, Rory Campbell-Lange (r...@campbell-lange.net) wrote: > I realise that for every row in my users table (which has a unique > integer field) I can update it if I construct a matching id field > against a random row from the testnames table. I can make my join table pretty well by using

Re: [GENERAL] Update table with random values from another table

2009-02-12 Thread Rory Campbell-Lange
On 12/02/09, Tom Lane (t...@sss.pgh.pa.us) wrote: > =?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?= writes: > > On Thu, Feb 12, 2009 at 1:10 PM, Rory Campbell-Lange > > wrote: > >> UPDATE > >> users > >> SET t_firstname = > >> (select firstname from testnames order by random() limit 1), > >> t_surname = > >

Re: [GENERAL] Update table with random values from another table

2009-02-12 Thread Rory Campbell-Lange
Hi Grzegorz Many thanks for your reply. On 12/02/09, Grzegorz Ja??kiewicz (gryz...@gmail.com) wrote: > actually forget about that generate_series() in sub queries, I just > realized that it won't do. > I don't have too much time to analyse and find solution, but > essentially you need to do it li

Re: [GENERAL] Update table with random values from another table

2009-02-12 Thread Tom Lane
=?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?= writes: > On Thu, Feb 12, 2009 at 1:10 PM, Rory Campbell-Lange > wrote: >> UPDATE >> users >> SET t_firstname = >> (select firstname from testnames order by random() limit 1), >> t_surname = >> (select lastname from testnames order by random() limit 1) >> WHER

Re: [GENERAL] Update table with random values from another table

2009-02-12 Thread Grzegorz Jaśkiewicz
actually forget about that generate_series() in sub queries, I just realized that it won't do. I don't have too much time to analyse and find solution, but essentially you need to do it like in my example. See, that's where normalization would help a lot. Ie, having a separate table for name, and

Re: [GENERAL] Update table with random values from another table

2009-02-12 Thread Grzegorz Jaśkiewicz
On Thu, Feb 12, 2009 at 1:10 PM, Rory Campbell-Lange wrote: >UPDATE >users >SET t_firstname = >(select firstname from testnames order by random() limit > 1), >t_surname = >(select lastname from testnames order by random() limit 1

[GENERAL] Update table with random values from another table

2009-02-12 Thread Rory Campbell-Lange
I have a test system for which I need to replace actual user's data (in 'users') with anonymised data from another table ('testnames') on postgres 8.3. The tricky aspect is that each row from testnames must be randomised to avoid each row in users being updated with the same value. I've been try

Re: [GENERAL] Update table with random values from another table

2009-02-12 Thread Rory Campbell-Lange
On 12/02/09, Rory Campbell-Lange (r...@campbell-lange.net) wrote: > I have a test system for which I need to replace actual user's data (in > 'users') with anonymised data from another table ('testnames') on > postgres 8.3. > > The tricky aspect is that each row from testnames must be randomised