BUG #14619: Before update trigger on foreign table fails to update values

From: andrew(dot)wheelwright(at)familysearch(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #14619: Before update trigger on foreign table fails to update values
Date: 2017-04-10 21:57:56
Message-ID: 20170410215756.25948.57696@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14619
Logged by: Andrew Wheelwright
Email address: andrew(dot)wheelwright(at)familysearch(dot)org
PostgreSQL version: 9.6.2
Operating system: CentOS 6.7
Description:

We recently upgraded our databases from 9.4 to 9.6.2.

I'm noticing a problem with some updates to foreign tables I wasn't seeing
before the upgrade (doesn't mean the problem wasn't there, however).

For the sake of simplicity, I'll call my servers Master and Client. There's
a table on Master I'll call standard_values. There's a foreign table object
on Client which points to Master's standard_values table.

The standard_values foreign table on Client has a before update trigger
ensures the updated_by field is set to session_user.

When a user updates a record on the foreign table, (e.g. update
standard_values set standard = 'Foo' where id = 42), the updated_by field is
not set as expected.

I've defined the trigger function as follows:

create or replace function set_updated_by()
return trigger language plpgsql as $$
begin
raise debug 'Before trigger updated_by: %', new.updated_by;
new.updated_by := session_user;
raise debug 'After trigger updated_by: %', new.updated_by;
return new;
end;
$$;

The trigger is attached to the table using the following command:

create trigger set_updated_by_before_standard_values_update
before update on standard_values
for each row execute procedure set_updated_by();

From the raise debug statements, I can see that the trigger is called and
sets the appropriate value but the value doesn't make it into the table on
the foreign server.

I suspect the foreign data wrapper is ignoring the value because it wasn't
part of the original update statement. I've observed that I can get the
correct value if I explicitly try to set a random value for 'updated_by' in
my update query.

I'm not really sure how to troubleshoot this further and would appreciate
any pointers.

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2017-04-11 00:57:25 Re: BUG #14618: pg_repack - waiting for 1 transactions to finish
Previous Message Ódor Balázs 2017-04-10 17:19:37 Re: BUG #14616: error message without schema