Обсуждение: Inherits is not encouraged?

Поиск
Список
Период
Сортировка

Inherits is not encouraged?

От
Emi Lu
Дата:
Good morning,

I have two questions about inherits under postgreSQL 8.0.15.


(1) Is possible that I could change the column of a table that is 
defined by Inherits?

e.g., t1(col1, col2, col3); create table tx(colx) Inherits (t1)
I'd like to get tx shown as (col1, colx, col2, col3).


(2) Logically, I have a table inherited from two other tables, but no 
more other columns. Will it not be encouraged to do so?

e.g., t1 (col1... coln)     t2 (col1... coln)
     create t3() Inherits (t1, t2) without OID


Thanks a lot!
Lu Ying




Re: Inherits is not encouraged?

От
Tom Lane
Дата:
Emi Lu <emilu@encs.concordia.ca> writes:
> (1) Is possible that I could change the column of a table that is 
> defined by Inherits?

> e.g., t1(col1, col2, col3); create table tx(colx) Inherits (t1)
> I'd like to get tx shown as (col1, colx, col2, col3).

No, you don't really have a lot of control over that.  It'll stick
non-inherited columns at the end.

> (2) Logically, I have a table inherited from two other tables, but no 
> more other columns. Will it not be encouraged to do so?

> e.g., t1 (col1... coln)
>       t2 (col1... coln)
>       create t3() Inherits (t1, t2) without OID

Sure, that's allowed.
        regards, tom lane


Re: Inherits is not encouraged?

От
Karsten Hilbert
Дата:
On Mon, Mar 09, 2009 at 07:55:35PM -0400, Tom Lane wrote:

> Emi Lu <emilu@encs.concordia.ca> writes:
> > (1) Is possible that I could change the column of a table that is 
> > defined by Inherits?
> 
> > e.g., t1(col1, col2, col3); create table tx(colx) Inherits (t1)
> > I'd like to get tx shown as (col1, colx, col2, col3).
> 
> No, you don't really have a lot of control over that.

"Explicit select list" would be one way (and the one that's
encouraged as good practice):
select col1, colx, col2, col3 from tx;

If that doesn't cut it (say, generic viewer which doesn't
know what is going to be viewed) - use a view over tx. Maybe
even "hide" the table tx as "table_tx" and name the view
itself "tx". Care needs to be taken then to either setup
appropriate rules or to make insert/update/delete go to
"table_tx".

Karsten
-- 
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346