Missing information about CREATE TRIGGER on temporary tables

Started by PG Bug reporting formabout 4 years ago3 messagesdocs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/14/sql-createtrigger.html
Description:

To be confirmed by the developer community...
The reference page about CREATE TRIGGER should indicate if it's allowed to
create triggers on temp tables.
This seems to be the supported, but I was wondering what happens with the
trigger name when created on a temp table.
It appears that no conflict can occur with other processes, and the same
trigger name can be used by different processes.
Checking the system tables, it appears that the trigger is created in user's
pg_my_temp_schema() ...

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: PG Bug reporting form (#1)
Re: Missing information about CREATE TRIGGER on temporary tables

On Tue, Mar 8, 2022 at 9:25 AM PG Doc comments form <noreply@postgresql.org>
wrote:

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/14/sql-createtrigger.html
Description:

To be confirmed by the developer community...
The reference page about CREATE TRIGGER should indicate if it's allowed to
create triggers on temp tables.
This seems to be the supported, but I was wondering what happens with the
trigger name when created on a temp table.
It appears that no conflict can occur with other processes, and the same
trigger name can be used by different processes.
Checking the system tables, it appears that the trigger is created in
user's
pg_my_temp_schema() ...

Assuming this was moderated and so delayed. Answered on the -sql list
email thread:

/messages/by-id/CAKFQuwZNZzgpo+P8bF6HG=VMq9ZZaw2kpvpgq1KaaL59NFVUTw@mail.gmail.com

In short, temporary tables are tables, and the naming behavior is
documented on this page.

David J.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: PG Bug reporting form (#1)
Re: Missing information about CREATE TRIGGER on temporary tables

PG Doc comments form <noreply@postgresql.org> writes:

The reference page about CREATE TRIGGER should indicate if it's allowed to
create triggers on temp tables.
This seems to be the supported, but I was wondering what happens with the
trigger name when created on a temp table.

The page already says

The name to give the new trigger. This must be distinct from the name
of any other trigger for the same table.

That seems to be sufficient. There's no reason to mention temp tables
explicitly, because the rule isn't any different for them.

If you want to confirm that the documentation knows what it's talking
about, you could have a look at the system catalogs. The table that
stores triggers is pg_trigger, and "\d pg_trigger" in psql shows

=# \d pg_trigger
Table "pg_catalog.pg_trigger"
Column | Type | Collation | Nullable | Default
----------------+--------------+-----------+----------+---------
oid | oid | | not null |
tgrelid | oid | | not null |
tgparentid | oid | | not null |
tgname | name | | not null |
...
Indexes:
"pg_trigger_oid_index" PRIMARY KEY, btree (oid)
"pg_trigger_tgconstraint_index" btree (tgconstraint)
"pg_trigger_tgrelid_tgname_index" UNIQUE CONSTRAINT, btree (tgrelid, tgname)

So the uniqueness constraint is on table's OID + trigger's name.
Schemas don't enter into it.

regards, tom lane