On Sat, 2004-01-24 at 13:21, C. Bensend wrote:
I've looked at this, and it seems to be on the same level as a quick
DROP/CREATE. Is there no way to "mirror" a table structure in real time?
Benny-
If I understand what you want correctly, inheritance seems like a pretty good option. Changes to the definition of a super table are inherited by the sub table immediately. Data will be preserved in both tables (except when you drop a column). This is NOT "on the same level as a quick DROP/CREATE".
The primary gotcha for you is that selects on super tables implicitly select from the super and all its children (see "select * from ONLY table" to prevent this).
Here's a proposal to get what you want: Create a super table bob_def and two sub tables bob and bob_test. Changes to the definition of bob_def (e.g., alter table add column...) will get immediately reflected in both children. You'll insert data into bob and bob_test; bob_def contains no rows. Selects on bob and bob_test are independent. In short, the definitions will always be consistent and the data will be completely independent. You could periodically truncate bob_test and insert ... select to mirror the data too.
A lesser option is to have bob_test inherit from bob, then use rules to enforce the ONLY keyword for select/insert/update on bob. The implementation of this option is less clear to me and there are a few likely gotchas.
CREATE TABLE test_bob AS ( SELECT * FROM bob WHERE '1' = '2' );
I don't understand why this does what you want... it requires explicit intervention (meaning not "real time") to mirror the table definition.
-Reece
--
Reece Hart, http://www.in-machina.com/~reece/, GPG:0x25EC91A0 0xD178AAF9
|