Inheritance question
Inheritance question
От:
"Raymond C. Rodgers" <rrodgers@bbnk.dhs.org>
Дата:
First, I want to confess that I am not an SQL expert or even remotely close. :-) Second, I believe I pretty much know the answer to my question, but I would like to have some confirmation if you fine people don't mind. My situation is this: I have a PHP script that some what dynamically generates two or more tables (but for the sake of this email lets stick with two), and a view to display the results of those tables. The tables might be defined like this: Table A ====== id bigint not null (Primary Key) b0 int not null b1 int not null b2 int not null Table B ====== id bigint not null (Primary Key) b0 int not null b1 int not null b2 int not null b3 int not null And the view ultimately maps those tables in combination with Table C which contains a serial column that the id in Tables A & B use. The view might have been created like this: create view View1 as select c.id, a.b0 as r0, a.b1 as r1, a.b2 as r2, b.b0 as r3, b.b1 as r4, b.b2 as r5, b.b3 as r6 from TableC c left join TableA a on c.id = a.id left join TableB b on c.id = b.id This results in a virtual table/view that contains all of the columns from tables A & B, in addition to another column from table C. That's fine for most of my purposes. I only recently learned about the inheritance features, and I was hoping that I could find a way to implement a table that is the child of tables A & B that would allow me to map the columns as I desire rather than automatically merging them. Based on the documentation and my own testing, I would have to say that this isn't possible in 8.1 (which I currently use) or 8.2 (which I'll be moving to soon). The question, and point, is this: Is there an alternate way of accomplishing read and write functionality similar to what inheritance offers but allowing me to map the columns as I desire? The read only view is nice, but it would save me a lot of work if I could take advantage of inheritance in this way. Thanks for your time and patience! Raymond
Re: Inheritance question
От:
Andrew Sullivan <ajs@crankycanuck.ca>
Дата:
On Thu, May 24, 2007 at 04:44:53PM -0700, Raymond C. Rodgers wrote: > The question, and point, is this: Is there an alternate way of > accomplishing read and write functionality similar to what inheritance > offers but allowing me to map the columns as I desire? The read only It isn't clear from your question whether the data in the tables is _the same_ in these cases. If so, then you could have various child tables inherit the parent, and the parent would be the largest of all the tables (the child tables without the columns in question would just have those columns null). But in general, my impression is that you don't want inheritance here. What you probably want is better normalization of your data on the way in. A -- Andrew Sullivan | ajs@crankycanuck.ca The fact that technology doesn't work is no bar to success in the marketplace. --Philip Greenspun