Re: Command Triggers - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Command Triggers
Date
Msg-id CA+TgmoZyS18rYFxaAjOVRLtdEe=oTNKoG2nFu_d6UzE-zyVvKw@mail.gmail.com
Whole thread Raw
In response to Re: Command Triggers  (Dimitri Fontaine <dimitri@2ndQuadrant.fr>)
Responses Re: Command Triggers  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Fri, Jan 20, 2012 at 12:14 PM, Dimitri Fontaine
<dimitri@2ndquadrant.fr> wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>> I think the OID is better than the name, but if it's easy to pass the
>> name and schema, then I'm fine with it.  But I do think this is one of
>
> It's quite easy to get name and schema from the command yes, here's an
> example of how I'm doing it for some commands:
>
>                case T_CreateStmt:
>                {
>                        CreateStmt *node = (CreateStmt *)parsetree;
>                        cmd->schemaname = RangeVarGetNamespace(node->relation);
>                        cmd->objectname = node->relation->relname;
>                        break;
>                }
>
>                case T_AlterTableStmt:
>                {
>                        AlterTableStmt *node = (AlterTableStmt *)parsetree;
>                        cmd->schemaname = RangeVarGetNamespace(node->relation);
>                        cmd->objectname = node->relation->relname;
>                        break;
>                }
>
>                case T_CreateExtensionStmt:
>                {
>                        cmd->schemaname = NULL;
>                        cmd->objectname = ((CreateExtensionStmt *)parsetree)->extname;
>                        break;
>                }
>
> Getting the OID on the other hand is much harder, because each command
> implements that part as it wants to, and DefineWhatever() functions are
> returning void. We could maybe have them return the main Oid of the
> object created, or we could have the CommandContext structure I'm using
> be a backend global variable that any command would stuff.
>
> In any case, adding support for the OID only works for after trigger
> when talking about CREATE commands and for before trigger if talking
> about DROP commands, assuming that the trigger procedure is run after
> we've been locating said Oid.
>
> It seems to me to be a couple orders of magnitude more work to get the
> Oid here compared to just get the schemaname and objectname. And getting
> those works in all cases as we take them from the command itself (we
> fill in the schema with the first search_path entry when it's not given
> explicitly in the command)
>
>  CREATE TABLE foo();
>  NOTICE:  tag:  CREATE TABLE
>  NOTICE:  enforce_local_style{public.foo}: foo

Hmm, OK.  But what happens if the user doesn't specify a schema name explicitly?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: JSON for PG 9.2
Next
From: Robert Haas
Date:
Subject: Re: Vacuum rate limit in KBps