Re: BUG #8198: ROW() literals not supported in an IN clause

Поиск
Список
Период
Сортировка
От Amit Kapila
Тема Re: BUG #8198: ROW() literals not supported in an IN clause
Дата
Msg-id 005101ce61b1$c5384cf0$4fa8e6d0$@kapila@huawei.com
обсуждение исходный текст
Ответ на Re: BUG #8198: ROW() literals not supported in an IN clause  (Rafał Rzepecki <divided.mind@gmail.com>)
Список pgsql-bugs
On Wednesday, June 05, 2013 5:34 AM Rafa=C5=82 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.
> >>
>=20
> If I'm right, the proper fix would be (patch 0001; caution, not
> tested):
>=20
> --- 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 =3D (Node *) lfirst(l);
>                 Node       *cmp;
>=20
> -               if (haveRowExpr)
> +               if (haveRowExpr && IsA(lexpr, RowExpr))
>                 {
> -                       if (!IsA(lexpr, RowExpr) ||
> -                               !IsA(rexpr, RowExpr))
> +                       if (!IsA(rexpr, RowExpr))
>                                 ereport(ERROR,
>=20
> (errcode(ERRCODE_SYNTAX_ERROR),
>                                    errmsg("arguments of row IN must =
all
> be row expressions"),
>=20
>=20
> 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):
>=20
> --- 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 =3D (Node *) lfirst(l);
>                 Node       *cmp;
>=20
> -               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 =3D make_row_comparison_op(pstate,
>=20
>           a->name,
>                                                           (List *)
> copyObject(((RowExpr *) lexpr)->args),
>=20
>           ((RowExpr *) rexpr)->args,
>=20
>           a->location);
> -               }
>                 else
>                         cmp =3D (Node *) make_op(pstate,
>                                                                    a-
> >name,
>=20

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=3D# select * from the_table where ROW('abc','def') in =
(row('foo','bar')::the_row,12);=20
ERROR:  arguments of row IN must all be row expressions=20
LINE 1: select * from the_table where ROW('abc','def') in (row('foo'...


With Regards,
Amit Kapila.

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Rafał Rzepecki
Дата:
Сообщение: Re: BUG #8198: ROW() literals not supported in an IN clause
Следующее
От: martin.schaefer@cadcorp.com
Дата:
Сообщение: BUG #8210: UTF8 column names corrupted by server