Re: Populating using Select

Поиск
Список
Период
Сортировка
От Andrew Sullivan
Тема Re: Populating using Select
Дата
Msg-id 20060926125256.GB12878@phlogiston.dyndns.org
обсуждение исходный текст
Ответ на Populating using Select  ("Ezequias Rodrigues da Rocha" <ezequias.rocha@gmail.com>)
Ответы Re: Populating using Select
Список 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'),    nameFROM    base.clientsGROUP 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


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Ezequias Rodrigues da Rocha"
Дата:
Сообщение: Populating using Select
Следующее
От: Kyle Bateman
Дата:
Сообщение: Finding context for error log