Re: Best practice for naming temp table trigger functions

From: Sebastien Flaesch <sebastien(dot)flaesch(at)4js(dot)com>
To: "pgsql-sql(at)lists(dot)postgresql(dot)org" <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Best practice for naming temp table trigger functions
Date: 2022-03-08 15:38:24
Message-ID: DBAP191MB1289C893FE38B9C831465376B0099@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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:

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

Seb
________________________________
From: Sebastien Flaesch <sebastien(dot)flaesch(at)4js(dot)com>
Sent: Monday, March 7, 2022 7:19 PM
To: pgsql-sql(at)lists(dot)postgresql(dot)org <pgsql-sql(at)lists(dot)postgresql(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2022-03-08 16:16:13 Re: Best practice for naming temp table trigger functions
Previous Message scott macri 2022-03-08 03:47:23 Re: ERROR: extra data after last expected column