pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: krking@zju.edu.cn
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17477: A crash bug in transformValuesClause()
Date: Mon, 09 May 2022 11:25:38 -0400
Message-ID: <3809468.1652109938@sss.pgh.pa.us> (raw)
In-Reply-To: <CAD21AoCF5EWSXUR6MOGUWeqqo5bGw=_4LHDbwhPjO4x+xQn9QA@mail.gmail.com>
References: <17477-0af3c6ac6b0a6ae0@postgresql.org>
	<CAD21AoCF5EWSXUR6MOGUWeqqo5bGw=_4LHDbwhPjO4x+xQn9QA@mail.gmail.com>

Masahiko Sawada <sawada.mshk@gmail.com> writes:
> It seems like transformValuesClause() cannot handle properly the value
> clause having a relation that has an empty column. Should we raise an
> error in this case?

Given that we try to support zero-column relations, I'm not sure why
we'd insist on disallowing zero-column VALUES.  I think the problem
is that the code in transformValuesClause needs to be tweaked to
make that work.  The attached quick hack seems to do the trick.

			regards, tom lane

Attachments:

allow-zero-columns-in-VALUES.patch (text/x-diff, 1.4K) download diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 0144284aa3..6b54e8e46d 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]); }

view thread (9+ messages)  latest in thread

Message-ID: <3809468.1652109938@sss.pgh.pa.us>
Permalink:  ../3809468.1652109938@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3809468.1652109938@sss.pgh.pa.us

 ·  · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, sawada.mshk@gmail.com, krking@zju.edu.cn, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17477: A crash bug in transformValuesClause()
  In-Reply-To: <3809468.1652109938@sss.pgh.pa.us>

* 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