Re: Inserting Multiple Random Rows - Mailing list pgsql-sql

From Tom Lane
Subject Re: Inserting Multiple Random Rows
Date
Msg-id 20335.1272474358@sss.pgh.pa.us
Whole thread Raw
In response to Inserting Multiple Random Rows  (Gary Chambers <gwchamb@gmail.com>)
Responses Re: Inserting Multiple Random Rows  (Gary Chambers <gwchamb@gmail.com>)
List pgsql-sql
Gary Chambers <gwchamb@gmail.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


pgsql-sql by date:

Previous
From: Gary Chambers
Date:
Subject: Inserting Multiple Random Rows
Next
From: Justin Graf
Date:
Subject: Re: Inserting Multiple Random Rows