LoginSignup
2
0

More than 1 year has passed since last update.

PG16:Error for row-level triggers with transition tables on partitioned tables

Last updated at Posted at 2022-12-18

はじめに

にゃーん。趣味でポスグレをやっている者だ。

この記事はPostgreSQL 16 全部ぬこ Advent Calendar 2022 19日目の記事です。
今回はパーティションテーブル&トリガに関するエラーメッセージの改善という小ネタについて書きます。

概要

項目 内容
タイトル Error for row-level triggers with transition tables on partitioned tables
Topic Bug Fixes
ステータス commited
Last Modified 2022-11-04
概要 パーティションテーブルに対して行レベルトリガを使おうとしたときのエラーメッセージの改善

変更内容

この変更は、パーティションテーブル(type=partitioned table)のテーブルに対して、行トリガを設定しようとしたときのエラーメッセージの改善です。

PostgreSQL 15.0/15.1

=# create table parted_trig (a int) partition by list (a);
CREATE TABLE
=# create function trigger_nothing() returns trigger language plpgsql as
=# $$ begin end; $$;
CREATE FUNCTION
=# create trigger failed after update on parted_trig referencing old
=# table as old_table for each row execute procedure trigger_nothing();
ERROR:  "parted_trig" is a partitioned table
DETAIL:  Triggers on partitioned tables cannot have transition tables.
=#

エラーメッセージ詳細の文言は「パーティション化されたテーブルのトリガーは、トランジションテーブルを持つことができない」という意味になっています。

しかし実際には、行レベルトリガではなくステートメントレベルトリガであればパーティションテーブルであっても設定は可能です。

=# create trigger failed after update on parted_trig referencing old
table as old_table for statement execute procedure trigger_nothing();
CREATE TRIGGER
=#

なので、行レベルトリガ作成時のエラーメッセージ詳細は不正確では?というのが問題のようです。

PostgreSQL 16

=# create table parted_trig (a int) partition by list (a);
CREATE TABLE
=# create function trigger_nothing() returns trigger language plpgsql as
$$ begin end; $$;
CREATE FUNCTION
=# create trigger failed after update on parted_trig referencing old
table as old_table for each row execute procedure trigger_nothing();
ERROR:  "parted_trig" is a partitioned table
DETAIL:  ROW triggers with transition tables are not supported on partitioned tables.
=#

PostgreSQL 16ではパーティションテーブルに対して行トリガを作成しようとしたときのメッセージ詳細が「トランジションテーブルを使用する ROW トリガーは、パーティションされたテーブルではサポートされていない」といった意味に変更されました。

おわりに

今回の記事で取り上げたのは、ささやかな修正ですが、こういう誤解を招かないメッセージの修正というのも使い勝手の向上という意味では大事ですよね。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0