Re: functions and creating

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: functions and creating
Дата
Msg-id 20060803224432.GA18273@winnie.fuhr.org
обсуждение исходный текст
Ответ на functions and creating  (Alex du Plessis <alexdup01@telkomsa.net>)
Список pgsql-novice
On Thu, Aug 03, 2006 at 09:08:02PM +0200, Alex du Plessis wrote:
> I need to create new databases on demand from my app.  Due to system
> constraints I cannot create the database from the app itself and was
> thinking of using a pl/psql function within the master database to
> perform this duty.
>
> However, it seems I cannot supply the name of the new database to the
> function via a function parameter.  Is there a way to do this and am
> just being ignorant?.  Does anybody know how to get around this one?

In some cases like this you can use PL/pgSQL's EXECUTE statement
to execute a dynamically-created statement; unfortunately this isn't
one of those cases because you can't execute CREATE DATABASE from
within a function.  If you try you'll get the following error:

  ERROR:  CREATE DATABASE cannot be executed from a function

One way for a function to execute forbidden commands is for the
function to use contrib/dblink to connect to the database and execute
the commands over that connection.

--
Michael Fuhr

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Garcia, Joshua"
Дата:
Сообщение: drop trigger all
Следующее
От: Ramon Orticio
Дата:
Сообщение: Re: updating postgres