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

От:
"Joseph Syjuco" <joseph@asti.dost.gov.ph>
Дата:
im new in postgresql (actually came from SQL Server) and i was trying a
script like this

insert into table1(field1,field2) values (select field1, field2 from table
2);

i dont know if this is possible (inserting a set of entries via resultset
from a select stmt in one command).  If anyone has any answers, or
workarounds pls do email me

Thanks


Re:

От:
"Joe Conway" <joseph.conway@home.com>
Дата:
> im new in postgresql (actually came from SQL Server) and i was trying a
> script like this
>
> insert into table1(field1,field2) values (select field1, field2 from table
> 2);
>
> i dont know if this is possible (inserting a set of entries via resultset
> from a select stmt in one command).  If anyone has any answers, or
> workarounds pls do email me

Well, that syntax doesn't work on SQL Server either.

I think what you want is:   insert into table1(field1,field2) select field1, field2 from table2;

HTH,

-- Joe




Re:

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Joseph Syjuco writes:

> im new in postgresql (actually came from SQL Server) and i was trying a
> script like this
>
> insert into table1(field1,field2) values (select field1, field2 from table
> 2);

The correct syntax is:

INSERT INTO table1 (field1, field2) SELECT field1, field2 FROM table2;

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re:

От:
Michael Davis <mdavis@sevainc.com>
Дата:
Try:
Create table table1(field1,field2) as (select field1, field2 from table2);


-----Original Message-----
From:	Joseph Syjuco [SMTP:joseph@asti.dost.gov.ph]
Sent:	Monday, September 03, 2001 3:03 AM
To:	pgsql-sql@postgresql.org
Subject:	

im new in postgresql (actually came from SQL Server) and i was trying a
script like this

insert into table1(field1,field2) values (select field1, field2 from table
2);

i dont know if this is possible (inserting a set of entries via resultset
from a select stmt in one command).  If anyone has any answers, or
workarounds pls do email me

Thanks


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

http://www.postgresql.org/search.mpl


Re:

От:
Stephan Szabo <sszabo@megazone23.bigpanda.com>
Дата:

On Mon, 3 Sep 2001, Joseph Syjuco wrote:

> im new in postgresql (actually came from SQL Server) and i was trying a
> script like this
> 
> insert into table1(field1,field2) values (select field1, field2 from table
> 2);
> 
> i dont know if this is possible (inserting a set of entries via resultset
> from a select stmt in one command).  If anyone has any answers, or
> workarounds pls do email me

You can, but you don't need to use values.

insert into table1(field1, field2) select field1, field2 from table2;
should do what you want.


Re: INSERT Syntax

От:
"Josh Berkus" <josh@agliodbs.com>
Дата:
Вложения:
Joseph,

> insert into table1(field1,field2) values (select field1, field2 from
> table
> 2);

Actually, that won't work in SQL Server either.  The correct syntax (for
both databases) is:

INSERT INTO table1 ( field1, field2 )
SELECT field1, field2 FROM table2;

The "VALUES" syntax is only appropriate if you are inserting a set of
constants with no SELECT statement involved.

-Josh Berkus


______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco
FAQ