Search Postgresql Archives

Re: Error in insert statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Relyea, Mike wrote on 16.07.2009 21:40:
I need help understanding what I'm doing wrong with an insert statement.
I'm running 8.3.7 on Windows and the DB is complaining about the select
statement in my insert statement.

When using a SELECT for an INSERT the values part is not needed in fact its incorrect syntax.

You need to run:

INSERT INTO "tblSpecs"
("CartridgeTypeID", "ColorID", "TestTypeID",
"ZoneID", "PaperID", "AttributeID", "Spec")
SELECT * FROM "tblTempSpecs";

But: using a "SELECT *" here is calling for trouble. You are relying on an implicit an not guaranteed order and number of columns.

Listing all the needed columns in the SELECT statement is much more robust.

Btw: you should create your tables without using double quotes, thus you can get rid of them when doing normal DML.

Out of curiosity: why do you prefix the table with "tbl"? Don't you know it's a table? Sounds like a strange naming scheme to me.

Thomas


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux