472,984 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,984 software developers and data experts.

Question on INSERT statement

Hello,

I'm wondering if the following behaviour is the correct one for
PostGreSQL (7.4 on UNIX).

I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching
the following request :

INSERT INTO temp_tab VALUES (1,2,3)

It will insert the values in the three first row whereas with informix
or db2 for exemple, it will return an error.

So is that normal ?

Geoffrey Kretz - Four J's Development Tools

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #1
2 3127
Richard Huxton wrote:
Geoffrey KRETZ wrote:

I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a
launching the following request :

INSERT INTO temp_tab VALUES (1,2,3)

It will insert the values in the three first row whereas with
informix or db2 for exemple, it will return an error.

So is that normal ?

Well, it's normal in the sense that other installations of PG will do
the same thing (and it's documented in the INSERT page of the
manuals). Whether it is desirable or according to the SQL standards is
another matter.

Anyone with a copy of the specs know what they say?

I think it's that, isn't it :

3) (...)If the <insert column list> is omitted, then an <insert column list>
that identifies all columns of T in the ascending sequence of
their ordinal positions within T is implicit.

Here's the complete SQL92 specifications about the insert clause, I
don't know if sthing has change with SQL99 spec

"13.8 <insert statement>

Function

Create new rows in a table.

Format

<insert statement> ::=
INSERT INTO <table name>
<insert columns and source>

<insert columns and source> ::=
[ <left paren> <insert column list> <right paren> ]
<query expression>
| DEFAULT VALUES

<insert column list> ::= <column name list>
Syntax Rules

1) The table T identified by the <table name> shall not be a read-
only table.

2) An <insert columns and source> that specifies DEFAULT VALUES is
equivalent to an <insert columns and source> that specifies a
<query expression> of the form

VALUES (DEFAULT, . . . )

where the number of "DEFAULT" entries is equal to the number of
columns of T.

3) No <column name> of T shall be identified more than once. If the
<insert column list> is omitted, then an <insert column list>
that identifies all columns of T in the ascending sequence of
their ordinal positions within T is implicit.

4) A column identified by the <insert column list> is an object
column.

5) Let QT be the table specified by the <query expression>. The
degree of QT shall be equal to the number of <column name>s in
the <insert column list>. The column of table T identified by
the i-th <column name> in the <insert column list> corresponds
with the i-th column of QT.

6) The Syntax Rules of Subclause 9.2, "Store assignment", apply to
corresponding columns of T and QT as TARGET and VALUE, respec-
tively.

Access Rules

1) Case:

a) If an <insert column list> is specified, then the applicable
<privileges> shall include INSERT for each <column name> in
the <insert column list>.

b) Otherwise, the applicable privileges shall include INSERT for
each <column name> in T.

Note: The applicable privileges for a <table name> are defined
in Subclause 10.3, "<privileges>".

2) Each <column name> in the <insert column list> shall identify a
column of T.

General Rules

1) If the access mode of the current SQL-transaction is read-only
and T is not a temporary table, then an exception condition is
raised: invalid transaction state.

2) Let B be the leaf generally underlying table of T.

3) The <query expression> is effectively evaluated before inserting
any rows into B.

4) Let Q be the result of that <query expression>.

Case:

a) If Q is empty, then no row is inserted and a completion con-
dition is raised: no data.

b) Otherwise, for each row R of Q:

i) A candidate row of B is effectively created in which the
value of each column is its default value, as specified in
the General Rules of Subclause 11.5, "<default clause>".
The candidate row includes every column of B.

ii) For every object column in the candidate row, the value of
the object column identified by the i-th <column name> in
the <insert column list> is replaced by the i-th value of
R.

iii) Let C be a column that is represented in the candidate row
and let SV be its value in the candidate row. The General
Rules of Subclause 9.2, "Store assignment", are applied to
C and SV as TARGET and VALUE, respectively.

iv) The candidate row is inserted into B.

Note: The data values allowable in the candidate row may be
constrained by a WITH CHECK OPTION constraint. The effect
of a WITH CHECK OPTION constraint is defined in the General
Rules of Subclause 11.19, "<view definition>".
Leveling Rules

1) The following restrictions apply for Intermediate SQL:

a) The leaf generally underlying table of T shall not be gen-
erally contained in the <query expression> immediately
contained in the <insert columns and source> except as the
<qualifier> of a <column reference>.

2) The following restrictions apply for Entry SQL in addition to
any Intermediate SQL restrictions:

a) The <query expression> that is contained in an <insert state-
ment> shall be a <query specification> or it shall be a <ta-
ble value constructor> that contains exactly one <row value
constructor> of the form "<left paren> <row value constructor
list> <right paren>", and each <row value constructor ele-
ment> of that <row value constructor list> shall be a <value
specification>.

b) If the data type of the target identified by the i-th <column
name> is an exact numeric type, then the data type of the i-
th item of the <insert statement> shall be an exact numeric
type.

c) If the data type of the target C identified by the i-th <col-
umn name> is character string, then the length in characters
of the i-th item of the <insert statement> shall be less than
or equal to the length of C.

d) The <insert columns and source> shall immediately contain a
<query expression>."

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

http://archives.postgresql.org

Nov 23 '05 #2
Geoffrey KRETZ <gk@4js.com> writes:
I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching
the following request :
INSERT INTO temp_tab VALUES (1,2,3)
It will insert the values in the three first row whereas with informix
or db2 for exemple, it will return an error.


This is an extension to the spec - per SQL92 it would be right to throw
an error. However Postgres has always behaved this way and we're not
likely to change it. (I think it's a hangover from PostQUEL.) Many
people find it to be a convenient behavior.

If you want an error then specify an explicit column list:

INSERT INTO temp_tab (f1,f2,f3,f4,f5) VALUES (1,2,3)

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MAB71 | last post by:
I wrote a procedure in SQL 6.5 which is something like CREATE PROCEDURE abc AS BEGIN TRAN xyz insert statement ..
20
by: akej via SQLMonster.com | last post by:
Hi, i have table with 15 columns CREATE TABLE . ( PRIMARY KEY , NULL , NULL , NULL , NULL , (50) NULL , NULL
9
by: Yaro | last post by:
Hello DB2/NT 8.1.3 Sorry for stupid questions. I am newbe in DB2. 1. How can I read *.sql script (with table and function definitions) into a database? Tool, command... 2. In Project Center...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
3
by: Rhino | last post by:
I just stumbled on something odd but I'm not sure if it's a bug in DB2 or something that is "working as designed." I have a simple SQL PL stored procedure which is doing an "INSERT SELECT..."...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
39
by: Daz | last post by:
Hello all, my question is more regarding advice on a script design. I have about 3600 entries in my database, the user submits a list, which is then checked against those in the database to...
10
by: =?ISO-8859-1?B?UOlw6g==?= | last post by:
Hi all. Im a newbie in PHP and im trying to upload a file to the server. I use a form to upload a pdf file and some text information about it. The client uploads the file and the system...
10
by: JohnO | last post by:
Hi All, This question is related to iSeries V5R4 and db2. I want to implement an AFTER DELETE trigger to save the deleted rows to an archive table, I initially defined it as a FOR EACH...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.