[BUG]: segfault during update - Mailing list pgsql-hackers

From Drouvot, Bertrand
Subject [BUG]: segfault during update
Date
Msg-id db5d97c8-f48a-51e2-7b08-b73d5434d425@amazon.com
Whole thread Raw
Responses Re: [BUG]: segfault during update
List pgsql-hackers

Hi hackers,

Here is a scenario that produces segfault during update (on version 12 and 13):

create table bdttrig (created_at timestamp without time zone not null default now(),col1 bool not null default false, col2 text not null default 'def', col3 char(6) not null default 'bdtbdt');
CREATE TABLE

CREATE or replace FUNCTION trigger_function()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS $$
BEGIN
IF (NEW != OLD) THEN
NEW.created_at = OLD.created_at;
RETURN NEW;
END IF;
RETURN OLD;
END;
$$
;

CREATE FUNCTION

create trigger bdt_trigger before update on bdttrig for each row EXECUTE function trigger_function();

CREATE TRIGGER

insert into bdttrig(col1) values (true);

INSERT 0 1

alter table bdttrig add column col4 text  not null default 'default';

ALTER TABLE

alter table bdttrig drop column col2;

ALTER TABLE

update bdttrig  set col1 = true;
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

I did some digging and found out and tested that the issue is fixed by this commit: https://github.com/postgres/postgres/commit/20d3fe9009ddbbbb3da3a2da298f922054b43f8c

So, we would need to back port this commit on 12 and 13.

Thanks

Bertrand

pgsql-hackers by date:

Previous
From: Jürgen Purtz
Date:
Subject: Re: Additional Chapter for Tutorial
Next
From: Tom Lane
Date:
Subject: Re: [BUG]: segfault during update