How to find owning schema in function

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: <pgsql-general(at)postgresql(dot)org>
Subject: How to find owning schema in function
Date: 2011-11-05 15:36:47
Message-ID: 590C7236EDF84F6CB786F6C7678A7167@dell2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

8.1+ database contains separate schemas for every company named company1,
company2, .... companyi.

order tables in those schemas contain trigger like for company1:

CREATE OR REPLACE FUNCTION dok_seq_trig() RETURNS "trigger"
AS $$BEGIN
IF NEW.tasudok IS NULL AND NEW.doktyyp!='O' THEN
NEW.tasudok = nextval( 'company1.'|| TG_RELNAME || '_'|| NEW.doktyyp
||'_seq');
END IF;

IF NEW.arvenumber IS NULL AND NEW.doktyyp='O' THEN
NEW.arvenumber = nextval( 'company1.'|| TG_RELNAME || '_'|| NEW.doktyyp
||'_seq');
END IF;

RETURN NEW;
END$$ LANGUAGE plpgsql STRICT;

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.

How to change this code so that instead of hard-coded schema name it
automatically uses the schema where trigger function is defined ?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2011-11-05 18:20:23 Re: Strange problem with create table as select * from table;
Previous Message Raymond O'Donnell 2011-11-05 15:24:36 Re: Function Question - Inserting into a table with foreign constraints