Re: Dynamically create scheme

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Mick van der Most van Spijk <mick(at)nederland(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Dynamically create scheme
Date: 2003-03-07 01:41:44
Message-ID: 200303070141.h271fi701627@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


I think you need to create a string variable on the function and use
EXECUTE.

---------------------------------------------------------------------------

Mick van der Most van Spijk wrote:
> Hi,
>
> I am writing an installscript and I would like to create a schema
> dynamically, based on a new input.
>
> -- this is the trigger that calls the install script
> CREATE TRIGGER tr_install_account AFTER INSERT
> ON accounts FOR EACH ROW
> EXECUTE PROCEDURE install();
>
> -- the install script
> 1 CREATE OR REPLACE FUNCTION install() RETURNS TRIGGER
> 2 AS '
> 3 BEGIN
> 4 INSERT INTO bedrijven (kvk, account) VALUES (''00000000'', NEW.account);
> 5 INSERT INTO settings (account, logo) VALUES (NEW.account, '''');
>
> 6 CREATE SCHEMA NEW.account;
> 7 RETURN NEW;
> 8 END;
> 9 ' LANGUAGE 'plpgsql';
>
> It goes wrong at line 9. I want to create a schema based on the accountname
> supplied. But i cant get it to work. Does anybody know how i get it to work
> or what reference i must read?
>
> Regards,
>
> Mick vd Most v Spijk
> --
> 'It never hurts to help' -- Eek the Cat
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2003-03-07 01:56:07 Re: password method in pg_hba.conf fails
Previous Message Justin Clift 2003-03-07 01:15:22 Re: replicating DDL statements