pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix two issues in deparsing.
7+ messages / 1 participants
[nested] [flat]

* pgsql: Fix two issues in deparsing.
@ 2026-10-19 21:51  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2026-10-19 21:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix two issues in deparsing.

If the target relation of UPDATE, DELETE, or MERGE has an alias,
we printed that "bare" (without AS or forced quoting), the same
as we do in FROM.  However, if that alias is "set", there's an
ambiguity with the SET keyword that must follow the relation
specification.  The parser would choose the wrong interpretation,
so that the dumped query would fail to reload.  The least surprising
and most future-proof fix seems to be to always print AS in these
contexts, as we already did in INSERT.

Also, we were insufficiently careful about parenthesizing the
left-hand argument of a SubLink (IN, op ANY/ALL, or row comparison),
so that the printed expression might not parse back with the intended
meaning depending on operator precedence.  This is only a problem in
"pretty-print" mode, since non-pretty mode fully parenthesizes every
operator.  So it isn't a hazard for pg_dump, but it still seems like
something to fix.  To do so, switch to using get_rule_expr_paren.
Presently that will add parens in some cases where it wouldn't really
be necessary, but that's better than the reverse, and it arguably
is helpful for readability anyway.

Author: Henson Choi <assam258@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAAAe_zDqXin5NeB5atRCbZqUdcMOeyXRqhan+tVp0F30OCURnw@mail.gmail.com
Discussion: https://postgr.es/m/CAAAe_zCy+D45Qd_br484F+V34y0BVA=hp_7cb=u6HysyMkE3UQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8113841f0d17082865b38c272eafa95f04c1f95d

Modified Files
--------------
src/backend/utils/adt/ruleutils.c         | 18 +++++++++++-----
src/test/regress/expected/create_view.out | 34 ++++++++++++++++++-------------
src/test/regress/expected/rules.out       |  8 ++++----
src/test/regress/sql/create_view.sql      |  5 ++++-
4 files changed, 41 insertions(+), 24 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix two issues in deparsing.
@ 2026-10-19 21:51  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2026-10-19 21:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix two issues in deparsing.

If the target relation of UPDATE, DELETE, or MERGE has an alias,
we printed that "bare" (without AS or forced quoting), the same
as we do in FROM.  However, if that alias is "set", there's an
ambiguity with the SET keyword that must follow the relation
specification.  The parser would choose the wrong interpretation,
so that the dumped query would fail to reload.  The least surprising
and most future-proof fix seems to be to always print AS in these
contexts, as we already did in INSERT.

Also, we were insufficiently careful about parenthesizing the
left-hand argument of a SubLink (IN, op ANY/ALL, or row comparison),
so that the printed expression might not parse back with the intended
meaning depending on operator precedence.  This is only a problem in
"pretty-print" mode, since non-pretty mode fully parenthesizes every
operator.  So it isn't a hazard for pg_dump, but it still seems like
something to fix.  To do so, switch to using get_rule_expr_paren.
Presently that will add parens in some cases where it wouldn't really
be necessary, but that's better than the reverse, and it arguably
is helpful for readability anyway.

Author: Henson Choi <assam258@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAAAe_zDqXin5NeB5atRCbZqUdcMOeyXRqhan+tVp0F30OCURnw@mail.gmail.com
Discussion: https://postgr.es/m/CAAAe_zCy+D45Qd_br484F+V34y0BVA=hp_7cb=u6HysyMkE3UQ@mail.gmail.com
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0497318e4422cbb9bff8c075a53a50b12065147c

Modified Files
--------------
src/backend/utils/adt/ruleutils.c         | 25 ++++++++++++++++++-------
src/test/regress/expected/create_view.out | 10 ++++++++--
src/test/regress/expected/returning.out   |  6 +++---
src/test/regress/expected/rules.out       | 12 ++++++------
src/test/regress/sql/create_view.sql      |  5 ++++-
5 files changed, 39 insertions(+), 19 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix two issues in deparsing.
@ 2026-10-19 21:51  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2026-10-19 21:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix two issues in deparsing.

If the target relation of UPDATE, DELETE, or MERGE has an alias,
we printed that "bare" (without AS or forced quoting), the same
as we do in FROM.  However, if that alias is "set", there's an
ambiguity with the SET keyword that must follow the relation
specification.  The parser would choose the wrong interpretation,
so that the dumped query would fail to reload.  The least surprising
and most future-proof fix seems to be to always print AS in these
contexts, as we already did in INSERT.

Also, we were insufficiently careful about parenthesizing the
left-hand argument of a SubLink (IN, op ANY/ALL, or row comparison),
so that the printed expression might not parse back with the intended
meaning depending on operator precedence.  This is only a problem in
"pretty-print" mode, since non-pretty mode fully parenthesizes every
operator.  So it isn't a hazard for pg_dump, but it still seems like
something to fix.  To do so, switch to using get_rule_expr_paren.
Presently that will add parens in some cases where it wouldn't really
be necessary, but that's better than the reverse, and it arguably
is helpful for readability anyway.

Author: Henson Choi <assam258@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAAAe_zDqXin5NeB5atRCbZqUdcMOeyXRqhan+tVp0F30OCURnw@mail.gmail.com
Discussion: https://postgr.es/m/CAAAe_zCy+D45Qd_br484F+V34y0BVA=hp_7cb=u6HysyMkE3UQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0da632e084842c36ec31d87adfc401b54ed7d7b2

Modified Files
--------------
src/backend/utils/adt/ruleutils.c         | 25 ++++++++++++++++++-------
src/test/regress/expected/create_view.out | 10 ++++++++--
src/test/regress/expected/returning.out   |  6 +++---
src/test/regress/expected/rules.out       | 12 ++++++------
src/test/regress/sql/create_view.sql      |  5 ++++-
5 files changed, 39 insertions(+), 19 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix two issues in deparsing.
@ 2026-10-19 21:51  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2026-10-19 21:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix two issues in deparsing.

If the target relation of UPDATE, DELETE, or MERGE has an alias,
we printed that "bare" (without AS or forced quoting), the same
as we do in FROM.  However, if that alias is "set", there's an
ambiguity with the SET keyword that must follow the relation
specification.  The parser would choose the wrong interpretation,
so that the dumped query would fail to reload.  The least surprising
and most future-proof fix seems to be to always print AS in these
contexts, as we already did in INSERT.

Also, we were insufficiently careful about parenthesizing the
left-hand argument of a SubLink (IN, op ANY/ALL, or row comparison),
so that the printed expression might not parse back with the intended
meaning depending on operator precedence.  This is only a problem in
"pretty-print" mode, since non-pretty mode fully parenthesizes every
operator.  So it isn't a hazard for pg_dump, but it still seems like
something to fix.  To do so, switch to using get_rule_expr_paren.
Presently that will add parens in some cases where it wouldn't really
be necessary, but that's better than the reverse, and it arguably
is helpful for readability anyway.

Author: Henson Choi <assam258@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAAAe_zDqXin5NeB5atRCbZqUdcMOeyXRqhan+tVp0F30OCURnw@mail.gmail.com
Discussion: https://postgr.es/m/CAAAe_zCy+D45Qd_br484F+V34y0BVA=hp_7cb=u6HysyMkE3UQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e79df9dd9f34115c13b038c7b22a8c3903e76e9b

Modified Files
--------------
src/backend/utils/adt/ruleutils.c         | 25 ++++++++++++++++++-------
src/test/regress/expected/create_view.out | 10 ++++++++--
src/test/regress/expected/returning.out   |  6 +++---
src/test/regress/expected/rules.out       | 12 ++++++------
src/test/regress/sql/create_view.sql      |  5 ++++-
5 files changed, 39 insertions(+), 19 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix two issues in deparsing.
@ 2026-10-19 21:51  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2026-10-19 21:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix two issues in deparsing.

If the target relation of UPDATE, DELETE, or MERGE has an alias,
we printed that "bare" (without AS or forced quoting), the same
as we do in FROM.  However, if that alias is "set", there's an
ambiguity with the SET keyword that must follow the relation
specification.  The parser would choose the wrong interpretation,
so that the dumped query would fail to reload.  The least surprising
and most future-proof fix seems to be to always print AS in these
contexts, as we already did in INSERT.

Also, we were insufficiently careful about parenthesizing the
left-hand argument of a SubLink (IN, op ANY/ALL, or row comparison),
so that the printed expression might not parse back with the intended
meaning depending on operator precedence.  This is only a problem in
"pretty-print" mode, since non-pretty mode fully parenthesizes every
operator.  So it isn't a hazard for pg_dump, but it still seems like
something to fix.  To do so, switch to using get_rule_expr_paren.
Presently that will add parens in some cases where it wouldn't really
be necessary, but that's better than the reverse, and it arguably
is helpful for readability anyway.

Author: Henson Choi <assam258@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAAAe_zDqXin5NeB5atRCbZqUdcMOeyXRqhan+tVp0F30OCURnw@mail.gmail.com
Discussion: https://postgr.es/m/CAAAe_zCy+D45Qd_br484F+V34y0BVA=hp_7cb=u6HysyMkE3UQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/91246c72695cdddf62003f6bf4c4ade511f134f4

Modified Files
--------------
src/backend/utils/adt/ruleutils.c         | 25 ++++++++++++++++++-------
src/test/regress/expected/create_view.out | 10 ++++++++--
src/test/regress/expected/rules.out       | 12 ++++++------
src/test/regress/sql/create_view.sql      |  5 ++++-
4 files changed, 36 insertions(+), 16 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix two issues in deparsing.
@ 2026-10-19 21:51  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2026-10-19 21:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix two issues in deparsing.

If the target relation of UPDATE, DELETE, or MERGE has an alias,
we printed that "bare" (without AS or forced quoting), the same
as we do in FROM.  However, if that alias is "set", there's an
ambiguity with the SET keyword that must follow the relation
specification.  The parser would choose the wrong interpretation,
so that the dumped query would fail to reload.  The least surprising
and most future-proof fix seems to be to always print AS in these
contexts, as we already did in INSERT.

Also, we were insufficiently careful about parenthesizing the
left-hand argument of a SubLink (IN, op ANY/ALL, or row comparison),
so that the printed expression might not parse back with the intended
meaning depending on operator precedence.  This is only a problem in
"pretty-print" mode, since non-pretty mode fully parenthesizes every
operator.  So it isn't a hazard for pg_dump, but it still seems like
something to fix.  To do so, switch to using get_rule_expr_paren.
Presently that will add parens in some cases where it wouldn't really
be necessary, but that's better than the reverse, and it arguably
is helpful for readability anyway.

Author: Henson Choi <assam258@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAAAe_zDqXin5NeB5atRCbZqUdcMOeyXRqhan+tVp0F30OCURnw@mail.gmail.com
Discussion: https://postgr.es/m/CAAAe_zCy+D45Qd_br484F+V34y0BVA=hp_7cb=u6HysyMkE3UQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f0595c3d839debdb140903621c1b44a4f4d86256

Modified Files
--------------
src/backend/utils/adt/ruleutils.c         | 25 ++++++++++++++++++-------
src/test/regress/expected/create_view.out | 10 ++++++++--
src/test/regress/expected/rules.out       | 10 +++++-----
src/test/regress/sql/create_view.sql      |  5 ++++-
4 files changed, 35 insertions(+), 15 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix two issues in deparsing.
@ 2026-10-19 21:51  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2026-10-19 21:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix two issues in deparsing.

If the target relation of UPDATE, DELETE, or MERGE has an alias,
we printed that "bare" (without AS or forced quoting), the same
as we do in FROM.  However, if that alias is "set", there's an
ambiguity with the SET keyword that must follow the relation
specification.  The parser would choose the wrong interpretation,
so that the dumped query would fail to reload.  The least surprising
and most future-proof fix seems to be to always print AS in these
contexts, as we already did in INSERT.

Also, we were insufficiently careful about parenthesizing the
left-hand argument of a SubLink (IN, op ANY/ALL, or row comparison),
so that the printed expression might not parse back with the intended
meaning depending on operator precedence.  This is only a problem in
"pretty-print" mode, since non-pretty mode fully parenthesizes every
operator.  So it isn't a hazard for pg_dump, but it still seems like
something to fix.  To do so, switch to using get_rule_expr_paren.
Presently that will add parens in some cases where it wouldn't really
be necessary, but that's better than the reverse, and it arguably
is helpful for readability anyway.

Author: Henson Choi <assam258@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAAAe_zDqXin5NeB5atRCbZqUdcMOeyXRqhan+tVp0F30OCURnw@mail.gmail.com
Discussion: https://postgr.es/m/CAAAe_zCy+D45Qd_br484F+V34y0BVA=hp_7cb=u6HysyMkE3UQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/697e1d3d5e271c40074005e5b0b5829b4f1e3b50

Modified Files
--------------
src/backend/utils/adt/ruleutils.c         | 25 ++++++++++++++++++-------
src/test/regress/expected/create_view.out | 10 ++++++++--
src/test/regress/expected/rules.out       | 10 +++++-----
src/test/regress/sql/create_view.sql      |  5 ++++-
4 files changed, 35 insertions(+), 15 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2026-10-19 21:51 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-19 21:51 pgsql: Fix two issues in deparsing. Tom Lane <tgl@sss.pgh.pa.us>
2026-10-19 21:51 pgsql: Fix two issues in deparsing. Tom Lane <tgl@sss.pgh.pa.us>
2026-10-19 21:51 pgsql: Fix two issues in deparsing. Tom Lane <tgl@sss.pgh.pa.us>
2026-10-19 21:51 pgsql: Fix two issues in deparsing. Tom Lane <tgl@sss.pgh.pa.us>
2026-10-19 21:51 pgsql: Fix two issues in deparsing. Tom Lane <tgl@sss.pgh.pa.us>
2026-10-19 21:51 pgsql: Fix two issues in deparsing. Tom Lane <tgl@sss.pgh.pa.us>
2026-10-19 21:51 pgsql: Fix two issues in deparsing. Tom Lane <tgl@sss.pgh.pa.us>

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