pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Kapila <amit.kapila@huawei.com>
To: 'Rafał Rzepecki' <divided.mind@gmail.com>
To: pgsql-bugs@postgresql.org
Cc: 'Tom Lane' <tgl@sss.pgh.pa.us>
Subject: Re: BUG #8198: ROW() literals not supported in an IN clause
Date: Wed, 5 Jun 2013 11:28:56 +0530
Message-ID: <005101ce61b1$c5384cf0$4fa8e6d0$@kapila@huawei.com> (raw)
In-Reply-To: <CAJu-ZiwPJCz1OkQ_Jx7PwLn_Hmdavk3KF=7JWULyLj5r-kEnzg@mail.gmail.com>
References: <E1UioKD-0007wM-Ta@wrigleys.postgresql.org>
	<51adc2f4.65cc440a.3921.ffffdd76SMTPIN_ADDED_BROKEN@mx.google.com>
	<CAJu-ZiwPJCz1OkQ_Jx7PwLn_Hmdavk3KF=7JWULyLj5r-kEnzg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On Wednesday, June 05, 2013 5:34 AM Rafał Rzepecki wrote:
> On Tue, Jun 4, 2013 at 12:35 PM, Amit Kapila <amit.kapila@huawei.com>
> wrote:
> > On Saturday, June 01, 2013 9:37 PM
> >
> >> Row type literals constructed with ROW() cause an error when used in
> >> an IN clause (string literals casted appropriately are allowed).
> This
> >> is especially problematic since many client libraries use these
> >> literals to pass values of row-type arguments, hence making it
> >> impossible to use them in IN-clause queries.
> >>
> 
> If I'm right, the proper fix would be (patch 0001; caution, not
> tested):
> 
> --- a/src/backend/parser/parse_expr.c
> +++ b/src/backend/parser/parse_expr.c
> @@ -1203,10 +1203,9 @@ transformAExprIn(ParseState *pstate, A_Expr *a)
>                 Node       *rexpr = (Node *) lfirst(l);
>                 Node       *cmp;
> 
> -               if (haveRowExpr)
> +               if (haveRowExpr && IsA(lexpr, RowExpr))
>                 {
> -                       if (!IsA(lexpr, RowExpr) ||
> -                               !IsA(rexpr, RowExpr))
> +                       if (!IsA(rexpr, RowExpr))
>                                 ereport(ERROR,
> 
> (errcode(ERRCODE_SYNTAX_ERROR),
>                                    errmsg("arguments of row IN must all
> be row expressions"),
> 
> 
> Since the restriction seems a rather arbitrary (at least I fail to see
> any reason for it), it can be removed altogether (patch 0002, not
> tested as well):
> 
> --- a/src/backend/parser/parse_expr.c
> +++ b/src/backend/parser/parse_expr.c
> @@ -1203,20 +1203,12 @@ transformAExprIn(ParseState *pstate, A_Expr *a)
>                 Node       *rexpr = (Node *) lfirst(l);
>                 Node       *cmp;
> 
> -               if (haveRowExpr)
> -               {
> -                       if (!IsA(lexpr, RowExpr) ||
> -                               !IsA(rexpr, RowExpr))
> -                               ereport(ERROR,
> -
> (errcode(ERRCODE_SYNTAX_ERROR),
> -                                  errmsg("arguments of row IN must
> all be row expressions"),
> -
> parser_errposition(pstate, a->location)));
> +               if (IsA(lexpr, RowExpr) && IsA(rexpr, RowExpr))
>                         cmp = make_row_comparison_op(pstate,
> 
>           a->name,
>                                                           (List *)
> copyObject(((RowExpr *) lexpr)->args),
> 
>           ((RowExpr *) rexpr)->args,
> 
>           a->location);
> -               }
>                 else
>                         cmp = (Node *) make_op(pstate,
>                                                                    a-
> >name,
> 

I had tried, both your patches have passed all regression tests (tested on Windows). I feel fixing it in a way similar to your Patch-1 would be
more appropriate as with Patch-1 it can generate meaningful error message for some cases like below:

postgres=# select * from the_table where ROW('abc','def') in (row('foo','bar')::the_row,12); 
ERROR:  arguments of row IN must all be row expressions 
LINE 1: select * from the_table where ROW('abc','def') in (row('foo'...


With Regards,
Amit Kapila.



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (6+ messages)  latest in thread

Message-ID: <005101ce61b1$c5384cf0$4fa8e6d0$@kapila@huawei.com>
Permalink:  ../005101ce61b1$c5384cf0$4fa8e6d0$@kapila@huawei.com/
Also on:    postgresql.org/message-id/005101ce61b1$c5384cf0$4fa8e6d0$@kapila@huawei.com

 · 

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: amit.kapila@huawei.com, divided.mind@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #8198: ROW() literals not supported in an IN clause
  In-Reply-To: <005101ce61b1$c5384cf0$4fa8e6d0$@kapila@huawei.com>
  References: <E1UioKD-0007wM-Ta@wrigleys.postgresql.org> <51adc2f4.65cc440a.3921.ffffdd76SMTPIN_ADDED_BROKEN@mx.google.com> <CAJu-ZiwPJCz1OkQ_Jx7PwLn_Hmdavk3KF=7JWULyLj5r-kEnzg@mail.gmail.com> <005101ce61b1$c5384cf0$4fa8e6d0$@kapila@huawei.com>

* 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