X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CFA2A9DCB9F for ; Mon, 5 Dec 2005 18:37:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65758-03 for ; Mon, 5 Dec 2005 18:37:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25]) by postgresql.org (Postfix) with ESMTP id 5CE879DCAF0 for ; Mon, 5 Dec 2005 18:37:24 -0400 (AST) Received: from TWMAIL.ESNCC.COM (static-66-173-159-28.t1.cavtel.net [66.173.159.28]) by svr2.postgresql.org (Postfix) with ESMTP id 70B64F0B57 for ; Mon, 5 Dec 2005 22:37:25 +0000 (GMT) Received: from spawar2i8uvlb9 ([150.125.117.63]) by TWMAIL.ESNCC.COM with Microsoft SMTPSVC(5.0.2195.6713); Mon, 5 Dec 2005 17:37:01 -0500 From: "Lane Van Ingen" To: "Michael Burke" , "PGSQL-SQL" Subject: Re: Database with "override" tables Date: Mon, 5 Dec 2005 17:37:00 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: <43948FD2.3030904@engtech.ca> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181 X-OriginalArrivalTime: 05 Dec 2005 22:37:01.0138 (UTC) FILETIME=[6889B320:01C5F9EC] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.332 required=5 tests=[RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.332 X-Spam-Level: * X-Archive-Number: 200512/27 X-Sequence-Number: 23569 I think I have a similar situation involving the naming of assets, where the usual asset description is used, but users can enter a description in a separate table which 'overrides' the original name with a name that is more familiar to the individual. IF THIS IS WHAT YOU WANT, it was accomplished by doing a UNION between two select statements, like this: select from foo1 union select from foo2 where ; Hope this helps. -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Michael Burke Sent: Monday, December 05, 2005 2:07 PM To: PGSQL-SQL Subject: [SQL] Database with "override" tables Hello, I am in a situation where I have various tables (including data such as a product list) that are read-only to me. I wish to provide the functionality of changing this table: Removing items, modifying items, creating new ones. My original idea is to use a second table that is formatted similarly to the first, read-only table. However, I can't just duplicate all the data and work in a separate table, as the original table may be modified by an outside source at any time. Generally, I prefer to use the updated data from the read-only table, unless there has been reason to modify it in the past -- in which case the update may be safely ignored, and I would continue to use the second table. The most effective set up I have come up with thus far is as follows: CREATE TABLE initial_table (initial_id SERIAL PRIMARY KEY, desc TEXT); CREATE TABLE override_table (override_id SERIAL PRIMARY KEY, initial_id INT, desc TEXT); An entry in override_table with an initial_id matching an initial_id in initial_table would take precedence over the entry in initial_table. A fairly simple SELECT statement can return the data I require: SELECT COALESCE(ot.desc, it.desc) FROM initial_table it FULL JOIN override_table ot ON it.initial_id = ot.initial_id; So far so good, but then when I need to reference data in those two tables from somewhere else, I need to reference both initial_id and override_id on the result set from that table. I also end up using COALESCE an uncomfortable amount (though, if this is required I will do so). I would prefer to treat the initial + override tables as a single SELECT set, but cannot come up with a way to do this cleanly, especially with regards to the IDs. I am willing to abandon this format of "overriding" the initial table if it is way off-course, provided that the initial data be considered read-only and update-able in the absence of "override" data. All suggestions are greatly appreciated! Thanks in advance, Mike. ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend