Gaurav Dadhania
Gaurav Dadhania

Reputation: 5337

PostgreSQL override inherited columns

Suppose I have an xmldoc relation which is as follows:

   Column     |            Type             | Modifiers                          
--------------+-----------------------------+-----------------
docid         | integer                     | not null  
create_date   | timestamp without time zone | not null 
type          | text                        | not null
xml           | xml                         | 

Now, let's say I create another table which just inherits from this table without any other columns. How can I, say, override 'xml' to be of type 'text'?

Currently, I'm getting :

ERROR:  cannot alter inherited column "xml"

So, how does overriding in DB inheritance work? [Specifically, I'm using PostgreSQL 8.3]

Upvotes: 5

Views: 3584

Answers (1)

mu is too short
mu is too short

Reputation: 434935

From the fine manual:

If the column name list of the new table contains a column name that is also inherited, the data type must likewise match the inherited column(s), and the column definitions are merged into one.

So you cannot override xml to be of type text. And as far as "how does overriding in DB inheritance work?" goes, it doesn't, you can't alter the interface (i.e. columns) through inheritance like that, you can only add new things or tighten constraints.

Are you familiar with Liskov substitution principle? Changing the column type would make the tables's common properties (AKA interfaces) incompatible.

Upvotes: 6

Related Questions