pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed(no subject)
5+ messages / 5 participants
[nested] [flat]
* (no subject)
@ 2001-09-03 09:02 Joseph Syjuco <joseph@asti.dost.gov.ph>
0 siblings, 4 replies; 5+ messages in thread
From: Joseph Syjuco @ 2001-09-03 09:02 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re:
@ 2001-09-03 17:05 Joe Conway <joseph.conway@home.com>
parent: Joseph Syjuco <joseph@asti.dost.gov.ph>
3 siblings, 0 replies; 5+ messages in thread
From: Joe Conway @ 2001-09-03 17:05 UTC (permalink / raw)
To: Joseph Syjuco <joseph@asti.dost.gov.ph>; pgsql-sql
> 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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re:
@ 2001-09-03 17:35 Peter Eisentraut <peter_e@gmx.net>
parent: Joseph Syjuco <joseph@asti.dost.gov.ph>
3 siblings, 0 replies; 5+ messages in thread
From: Peter Eisentraut @ 2001-09-03 17:35 UTC (permalink / raw)
To: Joseph Syjuco <joseph@asti.dost.gov.ph>; +Cc: pgsql-sql
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re:
@ 2001-09-03 17:45 Stephan Szabo <sszabo@megazone23.bigpanda.com>
parent: Joseph Syjuco <joseph@asti.dost.gov.ph>
3 siblings, 0 replies; 5+ messages in thread
From: Stephan Szabo @ 2001-09-03 17:45 UTC (permalink / raw)
To: Joseph Syjuco <joseph@asti.dost.gov.ph>; +Cc: pgsql-sql
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: INSERT Syntax
@ 2001-09-03 19:33 Josh Berkus <josh@agliodbs.com>
parent: Joseph Syjuco <joseph@asti.dost.gov.ph>
3 siblings, 0 replies; 5+ messages in thread
From: Josh Berkus @ 2001-09-03 19:33 UTC (permalink / raw)
To: Joseph Syjuco <joseph@asti.dost.gov.ph>; pgsql-sql
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
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2001-09-03 19:33 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-09-03 09:02 Joseph Syjuco <joseph@asti.dost.gov.ph>
2001-09-03 17:05 ` Re: Joe Conway <joseph.conway@home.com>
2001-09-03 17:35 ` Re: Peter Eisentraut <peter_e@gmx.net>
2001-09-03 17:45 ` Re: Stephan Szabo <sszabo@megazone23.bigpanda.com>
2001-09-03 19:33 ` Re: INSERT Syntax Josh Berkus <josh@agliodbs.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