Re: How to find owning schema in function

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to find owning schema in function
Date: 2011-11-06 09:18:48
Message-ID: 4EB650F8.4060502@compulab.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html style="direction: ltr;">
<head>
<meta content="text/html; charset=windows-1257"
http-equiv="Content-Type">
<style>body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body style="direction: ltr;" bidimailui-charset-is-forced="true"
bgcolor="#ffffff" text="#000000">
On 11/05/2011 05:36 PM, Andrus wrote:
<blockquote cite="mid:590C7236EDF84F6CB786F6C7678A7167(at)dell2"
type="cite">8.1+ database contains separate schemas for every
company named company1, company2, .... companyi.
<br>
<br>
order tables in those schemas contain trigger like for company1:
<br>
<br>
CREATE OR REPLACE FUNCTION dok_seq_trig() RETURNS "trigger"
<br>
AS $$BEGIN
<br>
IF NEW.tasudok IS NULL AND NEW.doktyyp!='O'  THEN
<br>
NEW.tasudok = nextval( 'company1.'|| TG_RELNAME || '_'||
NEW.doktyyp ||'_seq');
<br>
END IF;
<br>
<br>
IF NEW.arvenumber IS NULL AND NEW.doktyyp='O'  THEN
<br>
NEW.arvenumber = nextval( 'company1.'|| TG_RELNAME || '_'||
NEW.doktyyp ||'_seq');
<br>
END IF;
<br>
<br>
RETURN NEW;
<br>
END$$  LANGUAGE plpgsql STRICT;
<br>
<br>
This code has hard coded schema name 'company1'  . If new company
schema n is created from existing one, trigger functions needs
manual update to change schema to companyn.
<br>
<br>
How to change this code so that instead of hard-coded schema name
it automatically uses the schema where trigger function is defined
? <br>
</blockquote>
<a
href="http://www.postgresql.org/docs/8.2/interactive/plpgsql-trigger.html">http://www.postgresql.org/docs/8.2/interactive/plpgsql-trigger.html</a><br>
Shows all available variables. In this case - <span
class="Apple-style-span" style="color: rgb(0, 0, 0); font-family:
monospace; font-size: 13px; font-style: normal; font-variant:
normal; font-weight: normal; letter-spacing: normal; line-height:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; background-color: rgb(255, 255, 255);">TG_TABLE_SCHEMA</span><br>
<br>
Sim<br>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 2.3 KB

In response to

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2011-11-06 12:50:47 Re: Strange problem with create table as select * from table;
Previous Message Magnus Hagander 2011-11-06 08:21:59 Re: Some services of pgfoundry down?