Re: Triggers and Schema's.

Lists: pgsql-hackers
From: Steven Singer <ssinger(at)navtechinc(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: Triggers and Schema's.
Date: 2002-10-12 19:29:26
Message-ID: Pine.LNX.4.33.0210121925050.26039-100000@pcNavYkfAdm1.ykf.navtechinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I've been testing contrib/dbmirror with 7.3 and schema's and have come
across a problem.

SPI_getrelname(tg_relation) can be used by a trigger to get the name of
the table that the trigger was fired on. But that just gives the
tablename and not the schema that the table is in. If you have a schema
named "A" and a schema named "B" each with an employee table how can a
trigger determine if it was fired on A.employee or B.employee.

Thanks

--
Steven Singer ssinger(at)navtechinc(dot)com
Aircraft Performance Systems Phone: 519-747-1170 ext 282
Navtech Systems Support Inc. AFTN: CYYZXNSX SITA: YYZNSCR
Waterloo, Ontario ARINC: YKFNSCR


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Steven Singer <ssinger(at)navtechinc(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Triggers and Schema's.
Date: 2002-10-12 20:26:47
Message-ID: 13972.1034454407@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Steven Singer <ssinger(at)navtechinc(dot)com> writes:
> I've been testing contrib/dbmirror with 7.3 and schema's and have come
> across a problem.
> SPI_getrelname(tg_relation) can be used by a trigger to get the name of
> the table that the trigger was fired on. But that just gives the
> tablename and not the schema that the table is in. If you have a schema
> named "A" and a schema named "B" each with an employee table how can a
> trigger determine if it was fired on A.employee or B.employee.

You can do
get_namespace_name(RelationGetNamespace(tg_relation))
Is this sufficiently useful to justify adding an SPI_getrelnamespace()
function? I'm not very clear on the uses for SPI_getrelname(). Most
of the examples we have in contrib/ are using it for error messages,
which don't really need extra qualification IMHO. The ones that are
interpolating the result into queries are for the most part demonstrably
wrong anyway, because they fail to consider the possible need for double
quotes.

regards, tom lane


From: Steven Singer <ssinger(at)navtechinc(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Triggers and Schema's.
Date: 2002-10-15 01:42:15
Message-ID: Pine.LNX.4.33.0210150136500.32116-100000@pcNavYkfAdm1.ykf.navtechinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, 12 Oct 2002, Tom Lane wrote:

> Steven Singer <ssinger(at)navtechinc(dot)com> writes:

> get_namespace_name(RelationGetNamespace(tg_relation))
> Is this sufficiently useful to justify adding an SPI_getrelnamespace()
> function? I'm not very clear on the uses for SPI_getrelname(). Most
> of the examples we have in contrib/ are using it for error messages,

Thanks that function does the job.

I have no problem using that function(or other backend functions) from
triggers to do the job. If the idea behind SPI is that functions are only
supposed to access backend functions through SPI and not call the backend
directly then it probably should be added at some point for completeness
sake but I suspect other functions would fall into this category as well.

--
Steven Singer ssinger(at)navtechinc(dot)com
Aircraft Performance Systems Phone: 519-747-1170 ext 282
Navtech Systems Support Inc. AFTN: CYYZXNSX SITA: YYZNSCR
Waterloo, Ontario ARINC: YKFNSCR