Re: Error in insert statement

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Error in insert statement
Date: 2009-07-16 20:05:08
Message-ID: h3o15j$a0j$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message bricklen 2009-07-16 20:05:10 Re: Error in insert statement
Previous Message Relyea, Mike 2009-07-16 19:40:10 Error in insert statement