From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr> |
Cc: | Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)anarazel(dot)de>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Greg Smith <greg(at)2ndquadrant(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us> |
Subject: | Re: Command Triggers |
Date: | 2012-01-20 18:14:20 |
Message-ID: | CA+TgmoZyS18rYFxaAjOVRLtdEe=oTNKoG2nFu_d6UzE-zyVvKw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Jan 20, 2012 at 12:14 PM, Dimitri Fontaine
<dimitri(at)2ndquadrant(dot)fr> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2012-01-20 18:58:52 | Re: Vacuum rate limit in KBps |
Previous Message | Robert Haas | 2012-01-20 18:08:03 | Re: JSON for PG 9.2 |