Skip to content

Commit 8b39345

Browse files
committed
In INSERT/UPDATE, use the table's real tuple descriptor as target.
This back-patches commit 20d3fe9 into the v12 and v13 branches. At the time I thought that commit was not fixing any observable bug, but Bertrand Drouvot showed otherwise: adding a dropped column to the previously-considered scenario crashes v12 and v13, unless the dropped column happens to be an integer. That is, of course, because the tupdesc we derive from the plan output tlist fails to describe the dropped column accurately, so that we'll do the wrong thing with a tuple in which that column isn't NULL. There is no bug in pre-v12 branches because they already did use the table's real tuple descriptor for any trigger-returned tuple. It seems that this set of bugs can be blamed on the changes that removed es_trig_tuple_slot, though I've not attempted to pin that down precisely. Although there's no code change needed in HEAD, update the test case to include a dropped column there too. Discussion: https://postgr.es/m/db5d97c8-f48a-51e2-7b08-b73d5434d425@amazon.com Discussion: https://postgr.es/m/16644-5da7ef98a7ac4545@postgresql.org
1 parent d50e3b1 commit 8b39345

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

src/test/regress/expected/triggers.out

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,34 +216,56 @@ select * from trigtest;
216216

217217
drop table trigtest;
218218
-- Check behavior with an implicit column default, too (bug #16644)
219-
create table trigtest (a integer);
219+
create table trigtest (
220+
a integer,
221+
b bool default true not null,
222+
c text default 'xyzzy' not null);
220223
create trigger trigger_return_old
221224
before insert or delete or update on trigtest
222225
for each row execute procedure trigger_return_old();
223226
insert into trigtest values(1);
224227
select * from trigtest;
225-
a
226-
---
227-
1
228+
a | b | c
229+
---+---+-------
230+
1 | t | xyzzy
231+
(1 row)
232+
233+
alter table trigtest add column d integer default 42 not null;
234+
select * from trigtest;
235+
a | b | c | d
236+
---+---+-------+----
237+
1 | t | xyzzy | 42
238+
(1 row)
239+
240+
update trigtest set a = 2 where a = 1 returning *;
241+
a | b | c | d
242+
---+---+-------+----
243+
1 | t | xyzzy | 42
244+
(1 row)
245+
246+
select * from trigtest;
247+
a | b | c | d
248+
---+---+-------+----
249+
1 | t | xyzzy | 42
228250
(1 row)
229251

230-
alter table trigtest add column b integer default 42 not null;
252+
alter table trigtest drop column b;
231253
select * from trigtest;
232-
a | b
233-
---+----
234-
1 | 42
254+
a | c | d
255+
---+-------+----
256+
1 | xyzzy | 42
235257
(1 row)
236258

237259
update trigtest set a = 2 where a = 1 returning *;
238-
a | b
239-
---+----
240-
1 | 42
260+
a | c | d
261+
---+-------+----
262+
1 | xyzzy | 42
241263
(1 row)
242264

243265
select * from trigtest;
244-
a | b
245-
---+----
246-
1 | 42
266+
a | c | d
267+
---+-------+----
268+
1 | xyzzy | 42
247269
(1 row)
248270

249271
drop table trigtest;

src/test/regress/sql/triggers.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ select * from trigtest;
155155
drop table trigtest;
156156

157157
-- Check behavior with an implicit column default, too (bug #16644)
158-
create table trigtest (a integer);
158+
create table trigtest (
159+
a integer,
160+
b bool default true not null,
161+
c text default 'xyzzy' not null);
159162

160163
create trigger trigger_return_old
161164
before insert or delete or update on trigtest
@@ -164,7 +167,13 @@ create trigger trigger_return_old
164167
insert into trigtest values(1);
165168
select * from trigtest;
166169

167-
alter table trigtest add column b integer default 42 not null;
170+
alter table trigtest add column d integer default 42 not null;
171+
172+
select * from trigtest;
173+
update trigtest set a = 2 where a = 1 returning *;
174+
select * from trigtest;
175+
176+
alter table trigtest drop column b;
168177

169178
select * from trigtest;
170179
update trigtest set a = 2 where a = 1 returning *;

0 commit comments

Comments
 (0)