Skip site navigation (1) Skip section navigation (2)

Re: BUG #6095: Misleading error message: INSERT has more expressions than target columns

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gavin Flower" <gavin(dot)flower(at)archidevsys(dot)co(dot)nz>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6095: Misleading error message: INSERT has more expressions than target columns
Date: 2011-07-08 01:00:56
Message-ID: 9084.1310086856@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugs
"Gavin Flower" <gavin(dot)flower(at)archidevsys(dot)co(dot)nz> writes:
> In the 'INSERT INTO' construct: I think that psql should first check that
> the fields listed after the table name are valid, before checking that the
> number of columns specified is sufficient for the number of expressions.  

Hmm ... I think this would just move the set of unpleasant cases around.
Usually I find it's better if we check the count first.  For example, if
you accidentally stick an extra value into the VALUES list, and we
weren't checking the count first, you'd likely get weird
invalid-input-value complaints that stem from matching subsequent input
items to the wrong column.  In such cases it saves a lot of time if we
first point out the wrong number of values.

> Due to my poor eyesight: it took me a few minutes before I realized that I
> had used a fullstop '.' rather than a comma ',' in the list of columns. 
> There is neither a schema, nor a database, called 'id' - so I would have
> thought that pg should have been able to detect the error.

Actually, what you get if you change the number of VALUES columns is:

ERROR:  cannot assign to field "pay" of column "id" because its type integer is not a composite type
LINE 1: INSERT INTO wage (id. pay)
                          ^

This *is* valid syntax, if id is a composite-type column.

			regards, tom lane

In response to

pgsql-bugs by date

Next:From: Akira KurosawaDate: 2011-07-08 03:17:56
Subject: BUG #6096: ECPG set precision of double value to 14 digits
Previous:From: Gavin FlowerDate: 2011-07-08 00:29:08
Subject: BUG #6095: Misleading error message: INSERT has more expressions than target columns

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group