diff options
| author | Tom Lane | 2022-05-09 18:15:37 +0000 |
|---|---|---|
| committer | Tom Lane | 2022-05-09 18:15:37 +0000 |
| commit | fe20afaee8aac7838ed6e4a76baa83e547629582 (patch) | |
| tree | 4317539d93de3fc37ef65fcd3898f2b176130369 /src/backend/parser/analyze.c | |
| parent | 29904f5f2fdafbbb96ef3685fd361053b061aeb1 (diff) | |
Fix core dump in transformValuesClause when there are no columns.
The parser code that transformed VALUES from row-oriented to
column-oriented lists failed if there were zero columns.
You can't write that straightforwardly (though probably you
should be able to), but the case can be reached by expanding
a "tab.*" reference to a zero-column table.
Per bug #17477 from Wang Ke. Back-patch to all supported branches.
Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/backend/parser/analyze.c')
| -rw-r--r-- | src/backend/parser/analyze.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 0144284aa35..6b54e8e46df 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -1424,7 +1424,7 @@ static Query * transformValuesClause(ParseState *pstate, SelectStmt *stmt) { Query *qry = makeNode(Query); - List *exprsLists; + List *exprsLists = NIL; List *coltypes = NIL; List *coltypmods = NIL; List *colcollations = NIL; @@ -1508,6 +1508,9 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt) /* Release sub-list's cells to save memory */ list_free(sublist); + + /* Prepare an exprsLists element for this row */ + exprsLists = lappend(exprsLists, NIL); } /* @@ -1551,17 +1554,7 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt) /* * Finally, rearrange the coerced expressions into row-organized lists. */ - exprsLists = NIL; - foreach(lc, colexprs[0]) - { - Node *col = (Node *) lfirst(lc); - List *sublist; - - sublist = list_make1(col); - exprsLists = lappend(exprsLists, sublist); - } - list_free(colexprs[0]); - for (i = 1; i < sublist_length; i++) + for (i = 0; i < sublist_length; i++) { forboth(lc, colexprs[i], lc2, exprsLists) { @@ -1569,6 +1562,7 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt) List *sublist = lfirst(lc2); sublist = lappend(sublist, col); + lfirst(lc2) = sublist; } list_free(colexprs[i]); } |
