Skip to content
Advertisement

How to automatically create a comment on CREATE in Postgres?

I would like to create a trigger which gets fired once a table is created in a schema. This trigger should add a comment to the newly created table, something like:

With add_comment doing somthibg like:

However, it seems I can only add triggers on table level. How could I achieve to add comments to newly created tables in pure Postgres?

Advertisement

Answer

You need an EVENT TRIGGER.

First create a function:

Then attach it to an EVENT TRIGGER:

After you create a table it will be triggered:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement