• Michael Paquier's avatar
    Improve error handling of column references in expression transformation · ecfed4a1
    Michael Paquier authored
    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
    ecfed4a1
create_table.sql 28.2 KB