BUG #15752: Declarative partitions trigger with function attributes - empty attributes list on each partition

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

BUG #15752: Declarative partitions trigger with function attributes - empty attributes list on each partition

PG Bug reporting form
The following bug has been logged on the website:

Bug reference:      15752
Logged by:          Kamil Kukielka
Email address:      [hidden email]
PostgreSQL version: 11.2
Operating system:   Debian 4.9.0
Description:        

When trigger is created on partitioned table with execute function with
attributes, each partition calls function without defined values. That makes
triggers on partitioned tables little less useful.

```
-- partitioned table
CREATE TABLE IF NOT EXISTS test_part(id serial, description text) PARTITION
BY hash(id);
-- partitions
CREATE TABLE IF NOT EXISTS test_p0 PARTITION OF test_part FOR VALUES WITH
(MODULUS 2, REMAINDER 0);
CREATE TABLE IF NOT EXISTS test_p1 PARTITION OF test_part FOR VALUES WITH
(MODULUS 2, REMAINDER 1);
-- sample trigger function
CREATE OR REPLACE FUNCTION trigger_test() RETURNS trigger AS $$
BEGIN
  RAISE NOTICE 'TG_NARGS: %', TG_NARGS;
  RAISE NOTICE 'TG_ARGV: %', TG_ARGV::text;
  RETURN NULL;
END;
$$
LANGUAGE plpgsql;

CREATE TRIGGER test_with_part_trigger AFTER UPDATE ON test_part FOR EACH ROW
EXECUTE FUNCTION trigger_test('sample params', 1, 2, 3);

INSERT INTO test_part(description) SELECT 'table with partition';
UPDATE test_part SET description = 'table with partition';

/**
-- code result
NOTICE:  TG_NARGS: 0
NOTICE:  TG_ARGV: <NULL>
UPDATE 1
*/