pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve error handling of column references in expression transf
Date: Wed, 27 Mar 2019 12:05:55 +0000
Message-ID: <E1h97Jb-0004KB-No@gemulon.postgresql.org> (raw)

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(-)



Message-ID: <E1h97Jb-0004KB-No@gemulon.postgresql.org>
Permalink:  ../E1h97Jb-0004KB-No@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1h97Jb-0004KB-No@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Improve error handling of column references in expression transf
  In-Reply-To: <E1h97Jb-0004KB-No@gemulon.postgresql.org>
  References: <E1h97Jb-0004KB-No@gemulon.postgresql.org>

* 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