From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gary Chambers <gwchamb@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Inserting Multiple Random Rows
Date: Wed, 28 Apr 2010 13:05:58 -0400
Message-ID: <20335.1272474358@sss.pgh.pa.us> (raw)
In-Reply-To: <q2x302670f21004280922ic25b4f91k968effc6926a6243@mail.gmail.com>
References: <q2x302670f21004280922ic25b4f91k968effc6926a6243@mail.gmail.com>
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
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, gwchamb@gmail.com
Subject: Re: Inserting Multiple Random Rows
In-Reply-To: <20335.1272474358@sss.pgh.pa.us>
* 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