SQL function to access to `creating_extension`

Started by Yurii Rashkovskiiover 1 year ago3 messageshackers

Thread notes

1 note#feature#minor#enhancement
hackorum-bot#feature#minor#enhancement
hackorum-bot
1 day ago

@global #feature #minor #enhancement

#feature#minor#enhancement
Jump to latest
#1Yurii Rashkovskii
yrashk@omnigres.com

Hi,

I propose to introduce `pg_creating_extension()` function that would return
the OID of the extension being currently created (or `null` if none is).

The core motivation for it is to be able to establish data provenance in
tables created by extensions to be used in `pg_extension_config_dump`
configuration. This way, even if a secondary extension inserts data, it can
still be excluded from the dump by tracking data provenance in a column
with a default. Something like

```
create table my_config (
   --- ...
   extension_provenance oid default pg_creating_extension()
)
```

This would allow for a generalized exclusion in pg_extension_config_dump.

I've attached a draft patch for this simple function. I am happy to
finalize it with tests and documentation if there is a consensus on the
shape.

--
Founder at Omnigres
https://omnigres.com

Attachments:

t51469_1
v1-0001-pg_creating_extension-to-inspect-if-an-extension-is-.patchapplication/octet-stream; name=v1-0001-pg_creating_extension-to-inspect-if-an-extension-is-.patchDownload+15-1
#2Florents Tselai
florents.tselai@gmail.com
In reply to: Yurii Rashkovskii (#1)
Re: SQL function to access to `creating_extension`

On 19 Apr 2025, at 4:18 AM, Yurii Rashkovskii <yrashk@omnigres.com> wrote:

Hi,

I propose to introduce `pg_creating_extension()` function that would return the OID of the extension being currently created (or `null` if none is).

The core motivation for it is to be able to establish data provenance in tables created by extensions to be used in `pg_extension_config_dump` configuration. This way, even if a secondary extension inserts data, it can still be excluded from the dump by tracking data provenance in a column with a default. Something like

```
create table my_config (
--- ...
extension_provenance oid default pg_creating_extension()
)
```

This would allow for a generalized exclusion in pg_extension_config_dump.

I've attached a draft patch for this simple function. I am happy to finalize it with tests and documentation if there is a consensus on the shape.

--
Founder at Omnigres
https://omnigres.com <https://omnigres.com/><v1-0001-pg_creating_extension-to-inspect-if-an-extension-is-.patch>

Hi Yurii,

+1 from me.

I can see this being helpful, especially when dealing with shared tables or managing extension-specific data in configuration dumps.

#3Andrei Lepikhov
lepihov@gmail.com
In reply to: Yurii Rashkovskii (#1)
Re: SQL function to access to `creating_extension`

On 19/4/2025 03:18, Yurii Rashkovskii wrote:

This would allow for a generalized exclusion in pg_extension_config_dump.

I've attached a draft patch for this simple function. I am happy to
finalize it with tests and documentation if there is a consensus on the
shape.

I must admit that I rarely use the pg_extension_config_dump feature.
Additionally, the term 'secondary extension' is not entirely clear to me.

To ensure we are on the same page, it would be helpful to see the
specific case you are referring to as a regression test or TAP test
included with the patch.

--
regards, Andrei Lepikhov