Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 3ABD19FB220 for ; Tue, 26 Sep 2006 15:38:35 -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 99043-01 for ; Tue, 26 Sep 2006 18:38:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170]) by postgresql.org (Postfix) with ESMTP id 0E2DD9FB3B9 for ; Tue, 26 Sep 2006 15:38:23 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id 30so609692ugc for ; Tue, 26 Sep 2006 11:38:22 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=cVviG47c9HSDcwc6xu6TshjEjZSEYHCgX2MZGGiz7wBxizFRP6gbyQFfdVyhWP8G5X64qZauv3CLp//bCQCWIjOC5ThI2cUh/ExfGijCtWgfG5A+N9eCBGoYczcLgHBGfarfaEYgLZiCLUr5eNPhK9RuAgGb5doJXe3awLPvkZ4= Received: by 10.67.119.5 with SMTP id w5mr959341ugm; Tue, 26 Sep 2006 11:38:22 -0700 (PDT) Received: by 10.67.118.11 with HTTP; Tue, 26 Sep 2006 11:38:22 -0700 (PDT) Message-ID: <55c095e90609261138i2b0e204h984507ad35ce4f9@mail.gmail.com> Date: Tue, 26 Sep 2006 15:38:22 -0300 From: "Ezequias Rodrigues da Rocha" To: "Andrew Sullivan" Subject: Re: Populating using Select Cc: pgsql-sql@postgresql.org In-Reply-To: <20060926125256.GB12878@phlogiston.dyndns.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_14202_22645401.1159295902229" References: <55c095e90609260535r1951013ep15ec0d5a89c8a78a@mail.gmail.com> <20060926125256.GB12878@phlogiston.dyndns.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.696 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, HTML_40_50, HTML_MESSAGE, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/167 X-Sequence-Number: 26378 ------=_Part_14202_22645401.1159295902229 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thank you very much Andrew. Now I learned. Best regards From Brazil Ezequias R. da Rocha 2006/9/26, Andrew Sullivan : > > 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 > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org > --=20 =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Atenciosamente (Sincerely) Ezequias Rodrigues da Rocha =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- A pior das democracias ainda =E9 melhor do que a melhor das ditaduras The worst of democracies is still better than the better of dictatorships http://ezequiasrocha.blogspot.com/ ------=_Part_14202_22645401.1159295902229 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thank you very much Andrew. Now I learned.

Best regards
From Braz= il
Ezequias R. da Rocha

2006/9/2= 6, Andrew Sullivan <ajs@crankycan= uck.ca >:
O= n Tue, Sep 26, 2006 at 09:35:18AM -0300, Ezequias Rodrigues da Rocha wrote:
> I was trying to make something like this:
>
> Insert i= nto base.neigborhood values (nextval(), Select distinct name from
> b= ase.clients).

Not quite.

INSERT INTO base.neighborhood (colum= n list)
        SELECT nextval('sequenc= e name'),
          &n= bsp;     name
     &nb= sp;  FROM    base.clients
  &nbs= p;     GROUP BY name;

Note that this will g= ive 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
tab= le the results of a select from another).  If you thought thiswouldn't work, you maybe need a little more SQL practice than you
think you do.  Any of the excellent PostgreSQL books out ther= e should
cover this much.  Alternatively, the standard SQL int= roductions would
get you there.

A

--
Andrew Sullivan&nb= sp; | ajs@crankycanuck.ca
In the future this spectacle of the middle class= es shocking the avant-
garde will probably become the textbook definitio= n of Postmodernism.
        &nbs= p;       --Brad Holland

---------= ------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

   &n= bsp;           http://archives.postgresql.org



--
=3D-=3D-=3D-=3D-=3D-=3D-= =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-
            = ;            &n= bsp;         Atenciosamente (S= incerely)
          &n= bsp;            = ; Ezequias Rodrigues da Rocha
=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-= =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-
A pior das democracias ainda =E9 melho= r do que a melhor das ditaduras
The worst of democracies is still better than the better of dictatorshi= ps
http://ezequiasrocha.= blogspot.com/ ------=_Part_14202_22645401.1159295902229--