0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【PostgreSQL】あるトリガーが設定されていないテーブルを取得する

Last updated at Posted at 2023-09-05

やり方

以下は「publicスキーマ内で、UPDATED_ATカラムを持ち、set_timestampトリガーが設定されていないテーブルの一覧を取得する」クエリです。
細かい部分はコメントに記載しています。

SELECT c.table_name
FROM information_schema.columns c
  LEFT JOIN information_schema.triggers t ON t.event_object_table = c.table_name
    AND t.event_object_schema = c.table_schema -- 同名別スキーマ対策でスキーマも指定
    AND t.trigger_name = 'set_timestamp' -- JOIN対象はset_timestampトリガーのみ
WHERE c.table_schema = 'public'
  AND c.column_name ILIKE 'UPDATED_AT' -- 取得対象はUPDATED_ATのあるテーブル(定義は大文字だが、POSTGRES上は小文字扱いなため、ILIKEで検索している)
  AND t.trigger_name IS NULL; -- JOINできなかった = set_timestamp未設定のみ対象
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?