pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Populating using Select
3+ messages / 2 participants
[nested] [flat]

* Populating using Select
@ 2006-09-26 12:35 Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  2006-09-26 12:52 ` Re: Populating using Select Andrew Sullivan <ajs@crankycanuck.ca>
  0 siblings, 1 reply; 3+ messages in thread

From: Ezequias Rodrigues da Rocha @ 2006-09-26 12:35 UTC (permalink / raw)
  To: pgsql-sql

Hi list,

I need to populate a neigborhood table base on a select of another table
that already have a good amount of neigborhood saved.

Could someone tell me how it is possible ?

I was trying to make something like this:

Insert into base.neigborhood values (nextval(), Select distinct name from
base.clients).

I didn't try it but I suppose it will not work.


Regards ...

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                  Atenciosamente (Sincerely)
                        Ezequias Rodrigues da Rocha
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
A pior das democracias ainda é melhor do que a melhor das ditaduras
The worst of democracies is still better than the better of dictatorships
http://ezequiasrocha.blogspot.com/

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Populating using Select
  2006-09-26 12:35 Populating using Select Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
@ 2006-09-26 12:52 ` Andrew Sullivan <ajs@crankycanuck.ca>
  2006-09-26 18:38   ` Re: Populating using Select Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Andrew Sullivan @ 2006-09-26 12:52 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Populating using Select
  2006-09-26 12:35 Populating using Select Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  2006-09-26 12:52 ` Re: Populating using Select Andrew Sullivan <ajs@crankycanuck.ca>
@ 2006-09-26 18:38   ` Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Ezequias Rodrigues da Rocha @ 2006-09-26 18:38 UTC (permalink / raw)
  To: Andrew Sullivan <ajs@crankycanuck.ca>; +Cc: pgsql-sql

Thank you very much Andrew. Now I learned.

Best regards
From Brazil
Ezequias R. da Rocha

2006/9/26, Andrew Sullivan <ajs@crankycanuck.ca>:
>
> 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
>



-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                  Atenciosamente (Sincerely)
                        Ezequias Rodrigues da Rocha
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
A pior das democracias ainda é melhor do que a melhor das ditaduras
The worst of democracies is still better than the better of dictatorships
http://ezequiasrocha.blogspot.com/

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-09-26 18:38 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-09-26 12:35 Populating using Select Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2006-09-26 12:52 ` Andrew Sullivan <ajs@crankycanuck.ca>
2006-09-26 18:38   ` Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>

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