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

From Oliver Elphick
Subject Re: Create tables based on another table
Date
Msg-id 1064211459.26041.45.camel@linda.lfix.co.uk
Whole thread Raw
In response to Create tables based on another table  (Anshuman Kanwar <ansh@expertcity.com>)
List pgsql-novice
On Sun, 2003-09-21 at 19:23, Anshuman Kanwar wrote:
> Hi all,
>
> I want to have a table that lists all other tables in a database. For
> example:
,,,
>
> 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.
...
> What mechanism can I use to accomplish this ? Could anyone point me to any
> documentation ?

You need a trigger that runs after every INSERT.  If the data can change
and affect the subsidiary tables as a result, you may also need triggers
to run after UPDATE and/or DELETE.

See:
CREATE TRIGGER
CREATE FUNCTION
Procedural languages: PL/pgSQL (especially the chapter on using this
language in a trigger)

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "Therefore when thou doest thine alms, do not sound a
      trumpet before thee, as the hypocrites do in the
      synagogues and in the streets, that they may have
      glory of men. Verily I say unto you, They have their
      reward. But when thou doest alms, let not thy left
      hand know what thy right hand doeth; That thine alms
      may be in secret; and thy Father which seeth in secret
      himself shall reward thee openly."       Matthew 6:2-4


pgsql-novice by date:

Previous
From: Anshuman Kanwar
Date:
Subject: Create tables based on another table
Next
From: Aled Morris
Date:
Subject: Re: DTS