Обсуждение: create tables within functions

Поиск
Список
Период
Сортировка

create tables within functions

От
Demidem Mohamed Amine
Дата:
hello,

Can anyone help me create a function that creates a
table, in this way for example :

create function create_table(text) returns integer as
'
begin create table $1 (id integer, stuff text); return 0;
end;'
language plpgsql;

it does not work !!

thnx

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com


Re: create tables within functions

От
Stephan Szabo
Дата:
On Fri, 13 Jun 2003, Demidem Mohamed Amine wrote:

> hello,
>
> Can anyone help me create a function that creates a
> table, in this way for example :

See EXECUTE for a way to execute a query that you've built into
a string, for example, something like:

EXECUTE ''create table '' || $1 || '' (id integer, stuff text)'';

>
> create function create_table(text) returns integer as
> '
> begin
>   create table $1 (id integer, stuff text);
>   return 0;
> end;'
> language plpgsql;
>
> it does not work !!
>
> thnx
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
> http://calendar.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>



Re: create tables within functions

От
chester c young
Дата:
--- Demidem Mohamed Amine <demidem_amine@yahoo.com> wrote:
> hello,
> 
> Can anyone help me create a function that creates a table:

create function create_table( text ) returns integer as '
declare p_tab alias for $1; v_exec text;
begin v_exec := ''create table '' || p_tab || ''( id integer )''; execute v_exec;
end;
' language 'plpgsql'; 



__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com