Closed simonexmachina closed 9 years ago
We're adding _history
to tables that already exist and I'm concerned about some gotchas if we have data INHERITS data_history
. Take the following example:
CREATE TABLE "data_history" (LIKE "data");
ALTER TABLE "data" INHERIT "data_history";
data
and data_history
, and I can't see a way to remove the columns from the data
table ONLYALTER TABLE data_history
, rather than ALTER TABLE data
ALTER TABLE data_history DROP foo
will still leave the foo
column in the data tableYou are getting duplicate results for SELECT * FROM test_history
because queries to the parent table operate on the parent table and all child tables. You can avoid it by rewriting the query using ONLY
keyword: SELECT * FROM ONLY test_history
. Also, you have to rewrite UPDATE queries using this keyword: UPDATE ONLY test SET seq = 2
. That is how inheritance works in Postgres.
Of course, it is not an option if you are using a framework like Hibernate. If so, you have to keep both tables in sync manually.
You may well find this tutorial helpful.
Yes, you're right. I was sure I tried that, but obviously did something wrong. Thanks again!
I'd much prefer to say that
CREATE TABLE employees_history () INHERITS (employees)
, but this produces unexpected results. Is there any reason why this doesn't work as expected?For example:
If I change this to
CREATE TABLE "test" () INHERITS ("test_history")
then this works as expected: