Re: Best practice for naming temp table trigger functions - Mailing list pgsql-sql

From Sebastien Flaesch
Subject Re: Best practice for naming temp table trigger functions
Date
Msg-id DBAP191MB1289C893FE38B9C831465376B0099@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM
Whole thread Raw
In response to Best practice for naming temp table trigger functions  (Sebastien Flaesch <sebastien.flaesch@4js.com>)
Responses Re: Best practice for naming temp table trigger functions
List pgsql-sql

About CREATE TRIGGER names on temp tables:

  CREATE TRIGGER TT1_SRLT BEFORE INSERT ON TT1 FOR EACH ROW EXECUTE PROCEDURE TT1_8589_SRL()

I was wondering what happens with the trigger name when created on a temp table.

It appears that no conflict can occur, 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() ...

The doc should describe that it's allowed to create triggers on temp tables:


Seb

From: Sebastien Flaesch <sebastien.flaesch@4js.com>
Sent: Monday, March 7, 2022 7:19 PM
To: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>
Subject: Best practice for naming temp table trigger functions
 

EXTERNAL: Do not click links or open attachments if you do not recognize the sender.

Hello!

Temporary tables can get triggers in PostgreSQL.

Triggers are defined with a trigger function.

A temp table name is local to the current SQL session so there is no conflict with concurrent code doing the same CREATE TEMP TABLE mytable ...

However, user functions called by triggers are global to the schema and can enter in conflict...

What is the best practice, to avoid such issues?

I guess I could use some session id to build a unique function name.

But I would like to have that function dropped when the temp table is destroyed ...

Or, is there a way to define triggers directly with some anonymous code block?

Seb

pgsql-sql by date:

Previous
From: scott macri
Date:
Subject: Re: ERROR: extra data after last expected column
Next
From: "David G. Johnston"
Date:
Subject: Re: Best practice for naming temp table trigger functions