pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gavin Flower <gavin.flower@archidevsys.co.nz>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6095: Misleading error message: INSERT has more expressions than target columns
Date: Thu, 07 Jul 2011 21:00:56 -0400
Message-ID: <9084.1310086856@sss.pgh.pa.us> (raw)
In-Reply-To: <201107080029.p680T8dO058681@wwwmaster.postgresql.org>
References: <201107080029.p680T8dO058681@wwwmaster.postgresql.org>

"Gavin Flower" <gavin.flower@archidevsys.co.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



view thread (2+ messages)

Message-ID: <9084.1310086856@sss.pgh.pa.us>
Permalink:  ../9084.1310086856@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9084.1310086856@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, gavin.flower@archidevsys.co.nz
  Subject: Re: BUG #6095: Misleading error message: INSERT has more expressions than target columns
  In-Reply-To: <9084.1310086856@sss.pgh.pa.us>
  References: <201107080029.p680T8dO058681@wwwmaster.postgresql.org> <9084.1310086856@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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