Re: Create Table Dinamic

From: "mian wang" <lonelycat1984(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Create Table Dinamic
Date: 2008-08-07 01:41:32
Message-ID: 78da06c40808061841q7e0be00ag60c4003b67c24aac@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi:

CREATE OR REPLACE FUNCTION MakeTables ( NameTable text ) RETURNS void as
$$
BEGIN
execute 'CREATE TABLE '||$1||' ( id int, name text )';
END;
$$
LANGUAGE 'plpgsql';

2008/8/7 Anderson dos Santos Donda <andersondonda(at)gmail(dot)com>

> Hello All!
>
> Its my first time here in maillist and I started work with postgre on last
> moth.
>
> My questions is: Threre is a way to create tables dinamic?
>
> Example:
>
> To create a table we use CREATE TABLE TableName ......
>
> In my db, I have many tables with diferents names but with same colums
>
> Example:
>
> TableOne ( id int, name text );
> TableTwo ( id int, name text );
> TableThree ( id int, name text );
>
> So, I created a function to create me this tables with diferents names
>
> CREATE OR REPLACE FUNCTION MakeTables ( NameTable text ) RETURNS VOID
> $$
> BEGIN
> CREATE TABLE NameTable ( id int, name text );
> END;
> $$
> LANGUAGE 'plpgsql';
>
> But, the plpgsql or postgre don't accept this..
>
> So, How can I create a table with my function?
>
> Thanks for any helps!!!
>
> PS : If somebody want knows why I need to create this function, is because
> in my db have 1000 tables with the some colums, and each time I have a new
> client, I need to create this tables manually.
>

--
Kind Regards,
Mian

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2008-08-07 02:45:09 Re: C function on Windows 2003/XP
Previous Message Anderson dos Santos Donda 2008-08-07 01:10:21 Create Table Dinamic