Re: BUG #15623: Inconsistent use of default for updatable view
Amit Langote <langote_amit_f8@lab.ntt.co.jp>
From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: Dean Rasheed <dean.a.rasheed@gmail.com>,
Amit Langote <amitlangote09@gmail.com>
Cc: Roger Curley <rocurley@gmail.com>, pgsql-bugs@lists.postgresql.org,
PG Bug reporting form <noreply@postgresql.org>,
PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2019-02-28T07:46:57Z
Lists: pgsql-bugs, pgsql-hackers
On 2019/02/27 18:37, Dean Rasheed wrote: > On Tue, 12 Feb 2019 at 10:33, Dean Rasheed <dean.a.rasheed@gmail.com> wrote: >> Here's an updated patch ... > > So I pushed that. However, ... > > Playing around with it some more, I realised that whilst this appeared > to fix the reported problem, it exposes another issue which is down to > the interaction between rewriteTargetListIU() and rewriteValuesRTE() > --- for an INSERT with a VALUES RTE, rewriteTargetListIU() computes a > list of target attribute numbers (attrno_list) from the targetlist in > its original order, which rewriteValuesRTE() then relies on being the > same length (and in the same order) as each of the lists in the VALUES > RTE. That's OK for the initial invocation of those functions, but it > breaks down when they're recursively invoked for auto-updatable views. >> So actually, I think the right way to fix this is to give up trying to > compute attrno_list in rewriteTargetListIU(), and have > rewriteValuesRTE() work out the attribute assignments itself for each > column of the VALUES RTE by examining the rewritten targetlist. That > looks to be quite straightforward, and results in a cleaner separation > of logic between the 2 functions, per the attached patch. +1. Only rewriteValuesRTE needs to use that information, so it's better to teach it to figure it by itself. > I think that rewriteValuesRTE() should only ever see DEFAULT items for > columns that are simple assignments to columns of the target relation, > so it only needs to work out the target attribute numbers for TLEs > that contain simple Vars referring to the VALUES RTE. Any DEFAULT seen > in a column not matching that would be an error, but actually I think > such a thing ought to be a "can't happen" error because of the prior > checks during parse analysis, so I've used elog() to report if this > does happen. + if (attrno == 0) + elog(ERROR, "Cannot set value in column %d to DEFAULT", i); Maybe: s/Cannot/cannot/g + Assert(list_length(sublist) == numattrs); Isn't this Assert useless, because we're setting numattrs to list_length(<first-sublist>) and transformInsertStmt ensures that all sublists are same length? Thanks, Amit
Commits
-
Further fixing for multi-row VALUES lists for updatable views.
- 431471e1f2a2 9.4.22 landed
- 556fdd49c9e0 9.5.17 landed
- 133923aeb1b6 9.6.13 landed
- 0a08446308c8 10.8 landed
- 6ccb97337326 11.3 landed
- ed4653db8ca7 12.0 landed
-
Fix DEFAULT-handling in multi-row VALUES lists for updatable views.
- 41531e42d34f 12.0 landed
- fbec6fa38ade 11.3 landed
- 2b1971c0318b 10.8 landed
- d31e421d7df1 9.6.13 landed
- 90f91bfbd76f 9.5.17 landed
- 5a73edf050ed 9.4.22 landed