Re: Inserting Multiple Random Rows

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gary Chambers <gwchamb(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Inserting Multiple Random Rows
Date: 2010-04-28 17:05:58
Message-ID: 20335.1272474358@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Gary Chambers <gwchamb(at)gmail(dot)com> writes:
> INSERT INTO useraddrs(userid, addrdesc, city, stprov)
> SELECT u.userid, 'Home', c.cityname, c.stateabbr
> FROM users u, cities c
> WHERE u.userid NOT IN (SELECT userid FROM useraddrs)
> AND cid=(SELECT cid FROM cities ORDER BY RANDOM() LIMIT 1);

> I am able to achieve most of what I am trying to accomplish, but once
> the random number is selected, it doesn't change. What am I missing?

I believe the sub-SELECT will only get executed once, since it has no
dependency on the outer query. What were you expecting to happen?

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Justin Graf 2010-04-28 17:07:49 Re: Inserting Multiple Random Rows
Previous Message Gary Chambers 2010-04-28 16:22:23 Inserting Multiple Random Rows