Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]

like image 666
Gaurav Dadhania Avatar asked Feb 03 '11 02:02

Gaurav Dadhania


1 Answers

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.

like image 169
mu is too short Avatar answered Sep 25 '22 02:09

mu is too short