Create tables based on another table

From: Anshuman Kanwar <ansh(at)expertcity(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Create tables based on another table
Date: 2003-09-21 18:23:56
Message-ID: 571354A131635E42AE6C1F584F5F9B3A011EFB71@cabfranc.ad.corp.expertcity.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Oliver Elphick 2003-09-22 06:17:39 Re: Create tables based on another table
Previous Message santoso berkah 2003-09-20 23:14:30 Re: How to set up postgres user