Create tables based on another table - Mailing list pgsql-novice

From Anshuman Kanwar
Subject Create tables based on another table
Date
Msg-id 571354A131635E42AE6C1F584F5F9B3A011EFB71@cabfranc.ad.corp.expertcity.com
Whole thread Raw
Responses Re: Create tables based on another table
List pgsql-novice
Hi all,

I want to have a table that lists all other tables in a database. For
example:


table Project_List (
    project_id   integer;
    project_name text;
      project_type text;  -- can have values simple/complex
);

Now I want to automatically create a new table in the database whenever an
entry is made in this "Project_List". Based on "project_type", this new
table could have 2 different structures.


if $project_type is "simple"

    create table $project_name (     -- I want this to be filled in
                                     -- from the new row just added
                                     -- in the above table
        file_id integer;
        file_name text;
    );
else

    create table $project_name (

        file_id integer;
        file_name text;
        file_chksum text;
    );
fi


What mechanism can I use to accomplish this ? Could anyone point me to any
documentation ?

Thanks,
-ansh

pgsql-novice by date:

Previous
From: santoso berkah
Date:
Subject: Re: How to set up postgres user
Next
From: Oliver Elphick
Date:
Subject: Re: Create tables based on another table