From 3de122082dd701d8056d388190a425760b2bb3d6 Mon Sep 17 00:00:00 2001 From: jian he Date: Wed, 12 Aug 2026 13:00:09 +0800 Subject: [PATCH v50 1/1] Add a warning in select.sgml warning that pg_dump | pg_restore may fail because DEFINE clause does not allow expression have table qualification or column alias. --- doc/src/sgml/ref/select.sgml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml index d317b896e0..062dd6804e 100644 --- a/doc/src/sgml/ref/select.sgml +++ b/doc/src/sgml/ref/select.sgml @@ -1014,7 +1014,7 @@ WINDOW window_name AS ( frame_clause can be one of -{ RANGE | ROWS | GROUPS } frame_start [ frame_exclusion ] [ row_pattern_common_syntax ] +{ RANGE | ROWS | GROUPS } frame_start [ frame_exclusion ] { RANGE | ROWS | GROUPS } BETWEEN frame_start AND frame_end [ frame_exclusion ] [ row_pattern_common_syntax ] @@ -1207,7 +1207,6 @@ DEFINE definition_variable_name AS Note that the maximum number of unique pattern variables used in the PATTERN clause is 240. - If this limit is exceeded, an error will be raised. Additionally, the maximum nesting depth of pattern groups (parentheses) is 254 levels. However, pattern optimizations such as flattening nested sequences @@ -1244,6 +1243,28 @@ DEFINE definition_variable_name AS , and . + + + + According to the SQL standard, a column reference in a + DEFINE clause cannot be qualified by a table name or + alias; only row pattern variables may be used as qualifiers there. + Column names referenced in DEFINE must therefore be + unique across the entire FROM clause; an ambiguous + name is rejected. The workaround is to rename columns in the + FROM clause (for example, with a column alias in a + subquery). + + + + This also affects pg_dump and pg_restore. + A view can be created while a DEFINE referenced column name + is still unique, but if a later schema change (such as adding or renaming a + column) introduces a duplicate of that name, the view's definition keeps working while + its dumped definition no longer valid, restoring it fails with a + column reference is ambiguous error. + + -- 2.39.5 (Apple Git-154)