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: Best practice for naming temp table trigger functions
Date: 2022-03-07 18:19:37
Message-ID: DBAP191MB128959B0FE1ABE28C04ACDFFB0089@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message scott macri 2022-03-07 23:33:35 Re: ERROR: extra data after last expected column
Previous Message Rob Sargent 2022-03-07 09:57:57 Re: ERROR: extra data after last expected column