Re: Best practice for naming temp table trigger functions

Поиск
Список
Период
Сортировка
От Sebastien Flaesch
Тема Re: Best practice for naming temp table trigger functions
Дата
Msg-id DBAP191MB1289C893FE38B9C831465376B0099@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM
обсуждение исходный текст
Ответ на Best practice for naming temp table trigger functions  (Sebastien Flaesch <sebastien.flaesch@4js.com>)
Ответы Re: Best practice for naming temp table trigger functions  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: scott macri
Дата:
Сообщение: Re: ERROR: extra data after last expected column
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Best practice for naming temp table trigger functions