Обсуждение: insert into / select from / serial problem

Поиск
Список
Период
Сортировка

insert into / select from / serial problem

От
"tgh002"
Дата:
I am using a insert statement like:

INSERT INTO newtable
SELECT field1, field2 FROM anothertable

newtable structure is: serial, varchar, varchar

What syntax do I use to insert the serial field?   Ive tried something
like:
INSERT INTO newtable
SELECT nextval('newtable_id_seq'), field1, field2 FROM anothertable
but that doesnt work

Any ideas?  Greatly appreciated!



Re: insert into / select from / serial problem

От
Tom Lane
Дата:
"tgh002" <arnulfh@gmail.com> writes:
> I am using a insert statement like:
> INSERT INTO newtable
> SELECT field1, field2 FROM anothertable

> newtable structure is: serial, varchar, varchar

> What syntax do I use to insert the serial field?

I think you want to just let it default, which you'd do with, say,

INSERT INTO newtable (fielda, fieldb)
SELECT field1, field2 FROM anothertable
        regards, tom lane


Re: insert into / select from / serial problem

От
PFC
Дата:
On Wed, 10 Aug 2005 05:03:47 +0200, tgh002 <arnulfh@gmail.com> wrote:

> I am using a insert statement like:
>
> INSERT INTO newtable
> SELECT field1, field2 FROM anothertable
>
> newtable structure is: serial, varchar, varchar
>
> What syntax do I use to insert the serial field?   Ive tried something
> like:

Try :

INSERT INTO newtable (col1, col2) SELECT field1, field2 FROM anothertable

col1, col2 being the names of your columns that you want to put field1 and  
field2 into...

The serial will take care of itself.