X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C3DE48BA4BA for ; Wed, 16 Feb 2005 19:08:17 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36069-03 for ; Wed, 16 Feb 2005 19:07:55 +0000 (GMT) Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10]) by svr1.postgresql.org (Postfix) with ESMTP id 7B5348BA4C1 for ; Wed, 16 Feb 2005 18:52:30 +0000 (GMT) Received: (qmail 17477 invoked from network); 16 Feb 2005 19:53:03 +0100 Received: from unknown (HELO musicbox) (boutiquenumerique-lists@192.168.0.2) by boutiquenumerique.com with SMTP; 16 Feb 2005 19:53:03 +0100 Date: Wed, 16 Feb 2005 19:56:25 +0100 To: lucas@presserv.org, pgsql-sql@postgresql.org Subject: Re: Relation in tables References: <20050216134301.5myrfpr3ck6bmswc@www.presserv.org> From: PFC Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: In-Reply-To: <20050216134301.5myrfpr3ck6bmswc@www.presserv.org> User-Agent: Opera M2/7.54u1 (Linux, build 892) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/169 X-Sequence-Number: 20280 > Hello all... > I am starting in Postgresql... > And I have a question: > I am developing a DB system to manage products, but the products may be > separated by departaments (with its respectives coluns)... Like: > > CREATE TABLE products( > id serial primary key, > desc valchar(100), > ... > ); > > Okay, but the products is typed by "amount departament" and this > departament > should not have access to other coluns like "values, Money, etc...". > The "finances departament" may modify the data into products table, but > this > departament should not have access to coluns like "amounts, etc...". > > I' ve tried to create the products table with INHERITS but its not > right... > look: Use a view per department, which show/hide the columns according to your liking. Give each department a schema and put everything related to it inside for cleanliness. Use UPDATE triggers on the views, which in fact write to the products table, so that the departments can only update the columns you like. You can even make some columns readable but not writeable, by raising an exception if a modification is attempted on that column. If you want to reuse your code between departments, you will want all the views to have the same columns, so make them return NULL for the fields that they cannot see. Finally don't forget to make the products table inaccessible the departments.