Re: Prep object creation hooks, and related sepgsql updates - Mailing list pgsql-hackers

From Dimitri Fontaine
Subject Re: Prep object creation hooks, and related sepgsql updates
Date
Msg-id m2fwh8uh4b.fsf@2ndQuadrant.fr
Whole thread Raw
In response to Re: Prep object creation hooks, and related sepgsql updates  (Kohei KaiGai <kaigai@kaigai.gr.jp>)
Responses Re: Prep object creation hooks, and related sepgsql updates
List pgsql-hackers
Kohei KaiGai <kaigai@kaigai.gr.jp> writes:
> I found up a similar idea that acquires control on ProcessUtility_hook and
> save necessary contextual information on auto variable then kicks the
> original ProcessUtility_hook, then it reference the contextual information
> from object_access_hook.

In this case that would be an INSTEAD OF trigger, from which you can
call the original command with EXECUTE. You just have to protect
yourself against infinite recursion, but that's doable. See attached
example.

> For example, we don't want to apply permission checks on new relations
> constructed with make_new_heap. It shall be invoked when CLUSTER,
> VACUUM or ALTER TABLE, so we can skip permission checks when
> the saved command tag indicates these commands are currently running.

CREATE TRIGGER se_permission_checks
    INSTEAD OF COMMAND ALTER TABLE
       EXECUTE PROCEDURE se_permission_checks_alter_table();

In this INSTEAD OF trigger, protect against recursion, EXECUTE the
original ALTER TABLE statement which is given to you as a parameter,
enable the command trigger again.

Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support


Attachment

pgsql-hackers by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: patch for type privileges
Next
From: Stefan Keller
Date:
Subject: Re: odbc_fdw