Обсуждение: pgsql: Improve error handling of column references in expressiontransf

Поиск
Список
Период
Сортировка

pgsql: Improve error handling of column references in expressiontransf

От
Michael Paquier
Дата:
Improve error handling of column references in expression transformation

Column references are not allowed in default expressions and partition
bound expressions, and are restricted as such once the transformation of
their expressions is done.  However, trying to use more complex column
references can lead to confusing error messages.  For example, trying to
use a two-field column reference name for default expressions and
partition bounds leads to "missing FROM-clause entry for table", which
makes no sense in their respective context.

In order to make the errors generated more useful, this commit adds more
verbose messages when transforming column references depending on the
context.  This has a little consequence though: for example an
expression using an aggregate with a column reference as argument would
cause an error to be generated for the column reference, while the
aggregate was the problem reported before this commit because column
references get transformed first.

The confusion exists for default expressions for a long time, and the
problem is new as of v12 for partition bounds.  Still per the lack of
complaints on the matter no backpatch is done.

The patch has been written by Amit Langote and me, and Tom Lane has
provided the improvement of the documentation for default expressions on
the CREATE TABLE page.

Author: Amit Langote, Michael Paquier
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/20190326020853.GM2558@paquier.xyz

Branch
------
master

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

Modified Files
--------------
doc/src/sgml/ref/create_table.sgml         |  8 ++--
src/backend/catalog/heap.c                 | 16 ++-----
src/backend/parser/parse_expr.c            | 73 ++++++++++++++++++++++++++++++
src/backend/parser/parse_utilcmd.c         | 12 ++---
src/test/regress/expected/create_table.out | 58 +++++++++++++++++++-----
src/test/regress/sql/create_table.sql      | 14 ++++++
6 files changed, 147 insertions(+), 34 deletions(-)