Re: INSERT and parentheses

Lists: pgsql-hackers
From: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: INSERT and parentheses
Date: 2010-04-26 12:57:23
Message-ID: 4BD58DB3.4070605@cs.helsinki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

This came up on IRC today and I recall several instances of this during
the last two months or so, so I decided to send a patch. The problem in
question occurs when you have extra parentheses in an INSERT list:

INSERT INTO foo(a,b,c) SELECT (a,b,c) FROM ..; or
INSERT INTO foo(a,b,c) VALUES((0,1,2));

Both of these give you the same error:
ERROR: INSERT has more target columns than expressions

The first version is a lot more common and as it turns out, is sometimes
very hard to spot. This patch attaches a HINT message to these two
cases. The message itself could probably be a lot better, but I can't
think of anything.

Thoughts?

Regards,
Marko Tiikkaja

Attachment Content-Type Size
rowexpr.patch text/plain 1.6 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: INSERT and parentheses
Date: 2010-04-26 13:08:04
Message-ID: g2n603c8f071004260608s83b07b23u56a1d5f3af3150e3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Apr 26, 2010 at 8:57 AM, Marko Tiikkaja
<marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi> wrote:
> Hi,
>
> This came up on IRC today and I recall several instances of this during
> the last two months or so, so I decided to send a patch.  The problem in
> question occurs when you have extra parentheses in an INSERT list:
>
> INSERT INTO foo(a,b,c) SELECT (a,b,c) FROM ..; or
> INSERT INTO foo(a,b,c) VALUES((0,1,2));
>
> Both of these give you the same error:
> ERROR:  INSERT has more target columns than expressions
>
> The first version is a lot more common and as it turns out, is sometimes
> very hard to spot.  This patch attaches a HINT message to these two
> cases.  The message itself could probably be a lot better, but I can't
> think of anything.
>
> Thoughts?

I suggest adding it to the next CommitFest. Since I've never been
bitten by this, I can't get excited about the change, but I'm also not
arrogant enough to believe that everyone else's experiences are the
same as my own.

...Robert


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: INSERT and parentheses
Date: 2010-04-26 13:13:54
Message-ID: 20100426131354.GA21875@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> > The first version is a lot more common and as it turns out, is sometimes
> > very hard to spot.  This patch attaches a HINT message to these two
> > cases.  The message itself could probably be a lot better, but I can't
> > think of anything.
> >
> > Thoughts?
>
> I suggest adding it to the next CommitFest. Since I've never been
> bitten by this, I can't get excited about the change, but I'm also not
> arrogant enough to believe that everyone else's experiences are the
> same as my own.

Not to be a pain, but the hint really is kind of terrible.. It'd
probably be better if you included somewhere that the insert appears to
be a single column with a record-type rather than multiple columns of
non-composite type..

Thanks,

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: INSERT and parentheses
Date: 2010-04-26 14:20:06
Message-ID: 17319.1272291606@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> Not to be a pain, but the hint really is kind of terrible.. It'd
> probably be better if you included somewhere that the insert appears to
> be a single column with a record-type rather than multiple columns of
> non-composite type..

I don't much care for the test, either. AFAICS, a hint like this would
only be appropriate for a RowExpr item, *not* a Var. It might also be
worth checking the number of items in the RowExpr before deciding that
the hint is appropriate.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: INSERT and parentheses
Date: 2010-05-31 19:52:56
Message-ID: 201005311952.o4VJqu609325@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I have added this to the next commit-fest:

https://commitfest.postgresql.org/action/commitfest_view?id=6

---------------------------------------------------------------------------

Marko Tiikkaja wrote:
> Hi,
>
> This came up on IRC today and I recall several instances of this during
> the last two months or so, so I decided to send a patch. The problem in
> question occurs when you have extra parentheses in an INSERT list:
>
> INSERT INTO foo(a,b,c) SELECT (a,b,c) FROM ..; or
> INSERT INTO foo(a,b,c) VALUES((0,1,2));
>
> Both of these give you the same error:
> ERROR: INSERT has more target columns than expressions
>
> The first version is a lot more common and as it turns out, is sometimes
> very hard to spot. This patch attaches a HINT message to these two
> cases. The message itself could probably be a lot better, but I can't
> think of anything.
>
> Thoughts?
>
>
> Regards,
> Marko Tiikkaja

[ Attachment, skipping... ]

>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ None of us is going to be here forever. +