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 4E4259DCD03 for ; Tue, 6 Dec 2005 11:10:56 -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 26757-01-2 for ; Tue, 6 Dec 2005 11:10:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from TWMAIL.ESNCC.COM (static-66-173-159-28.t1.cavtel.net [66.173.159.28]) by postgresql.org (Postfix) with ESMTP id 61B659DCD53 for ; Tue, 6 Dec 2005 11:10:52 -0400 (AST) Received: from spawar2i8uvlb9 ([150.125.117.63]) by TWMAIL.ESNCC.COM with Microsoft SMTPSVC(5.0.2195.6713); Tue, 6 Dec 2005 10:10:56 -0500 From: "Lane Van Ingen" To: "Michael Burke" Cc: "PGSQL-SQL" Subject: Re: Database with "override" tables Date: Tue, 6 Dec 2005 10:10:55 -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: <4395A650.9000607@engtech.ca> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181 Importance: Normal X-OriginalArrivalTime: 06 Dec 2005 15:10:56.0970 (UTC) FILETIME=[424382A0:01C5FA77] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.666 required=5 tests=[AWL=0.666] X-Spam-Score: 0.666 X-Spam-Level: X-Archive-Number: 200512/43 X-Sequence-Number: 23585 Not quite sure how to answer this, but one thought does occur to me: I was perhaps assuming that an override table would override an entire record in the 'original' table(that is what we are doing), and we require that critical fields in the override field be NOT NULL (and in some cases, provide DEFAULT values). Will that help? -----Original Message----- From: Michael Burke [mailto:michael@engtech.ca] Sent: Tuesday, December 06, 2005 9:55 AM To: Lane Van Ingen Cc: PGSQL-SQL Subject: Re: [SQL] Database with "override" tables Lane Van Ingen wrote: >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. > > > That almost works, and it is a much cleaner query than I had before. However, there's a possibility that some columns in the overridden table are NULL (indicating that the original value should be used). So, a particular asset may contain a description and price; the price may be NULL, meaning the read-only value should be used, but the user may have attached a special description as we previously outlined. What I'm looking for is the ability to, perhaps, "overlay" foo2 onto foo1, joined on foo1_id. Then, NULL values in foo2 become "transparent" and we see the foo1 values behind them. Presently I am using COALESCE() for every pair individually, ie. COALESCE(foo2.price, foo1.price), COALESCE(foo2.descr, foo1.descr), ... and then doing a FULL JOIN. This works. I'm starting to wonder if it's worth the extra hassle, I may just use your suggested UNION method instead. Thanks again, Mike.