Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 253B79FB31A for ; Tue, 26 Sep 2006 09:53:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 30157-10 for ; Tue, 26 Sep 2006 12:53:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from main2.mycybernet.net (main2.mycybernet.net [209.222.63.140]) by postgresql.org (Postfix) with ESMTP id D275F9FB2B4 for ; Tue, 26 Sep 2006 09:53:02 -0300 (ADT) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227] helo=phlogiston.dydns.org) by main2.mycybernet.net with esmtp (Exim 4.62) (envelope-from ) id 1GSChv-00054E-ET for pgsql-sql@postgresql.org; Tue, 26 Sep 2006 09:10:43 -0400 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 0B3FC4051; Tue, 26 Sep 2006 08:52:56 -0400 (EDT) Date: Tue, 26 Sep 2006 08:52:56 -0400 From: Andrew Sullivan To: pgsql-sql@postgresql.org Subject: Re: Populating using Select Message-ID: <20060926125256.GB12878@phlogiston.dyndns.org> References: <55c095e90609260535r1951013ep15ec0d5a89c8a78a@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55c095e90609260535r1951013ep15ec0d5a89c8a78a@mail.gmail.com> User-Agent: Mutt/1.5.9i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200609/164 X-Sequence-Number: 26375 On Tue, Sep 26, 2006 at 09:35:18AM -0300, Ezequias Rodrigues da Rocha wrote: > I was trying to make something like this: > > Insert into base.neigborhood values (nextval(), Select distinct name from > base.clients). Not quite. INSERT INTO base.neighborhood (column list) SELECT nextval('sequence name'), name FROM base.clients GROUP BY name; Note that this will give you a different number for each of the names. If what you want is for them all to have the same number, then perform the nextval and then call currval() on the sequence. By the way, this is a pretty common use of SQL (inserting into one table the results of a select from another). If you thought this wouldn't work, you maybe need a little more SQL practice than you think you do. Any of the excellent PostgreSQL books out there should cover this much. Alternatively, the standard SQL introductions would get you there. A -- Andrew Sullivan | ajs@crankycanuck.ca In the future this spectacle of the middle classes shocking the avant- garde will probably become the textbook definition of Postmodernism. --Brad Holland