Обсуждение: "Reverse" inheritance?

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

"Reverse" inheritance?

От
Tim Uckun
Дата:
I am trying to make postgres tables work like an object hierarchy. As an example I have done this.

drop table if exists os.linux cascade;
create table os.linux
(
script_name character varying(255) NOT NULL,
script_body text,
CONSTRAINT os_linux_pkey PRIMARY KEY (script_name)
);

drop table if exists os.red_hat;

CREATE TABLE os.red_hat
(
CONSTRAINT os_red_hat_pkey PRIMARY KEY (script_name)
)INHERITS (os.linux);

drop table if exists os.debian;
CREATE TABLE os.debian
(
CONSTRAINT os_debian_pkey PRIMARY KEY (script_name)
)INHERITS (os.linux);


insert into os.linux(script_name, script_body) VALUES ('package', 'tgz' );
insert into os.linux(script_name, script_body) VALUES ('awk', 'awk' );
insert into os.debian(script_name, script_body) values( 'package', 'apt');
insert into os.red_hat(script_name, script_body) values( 'package', 'yum');

When I do  SELECT * from os.debian I would like to get two records one where the package is 'apt' and one where the awk is 'awk'.

So the package row is overridden in the child but it inherits the parent row.

Is there a way to do this?  

Ideally I would like to have a deeper hierarchy like nix -> linux -> debian -> ubuntu -> ubuntu_16_04

so that when I select from ubuntu_16_04 I get all the rows from all the parent tables but properly overridden so they don't union.

Thanks.

Re: "Reverse" inheritance?

От
"David G. Johnston"
Дата:
On Mon, Apr 3, 2017 at 7:07 PM, Tim Uckun <timuckun@gmail.com> wrote:
I am trying to make postgres tables work like an object hierarchy. As an example I have done this.

​I suspect you are barking up the wrong tree ;)

You are probably better off incorporating something like the "ltree" type to encode the taxonomy.


I haven't had a chance to leverage it myself but the concept it embodies is solid.

David J.

Re: "Reverse" inheritance?

От
Tim Uckun
Дата:
I have thought of doing something like a single table inheritance and it could be done but I thought this might be a little more elegant.

On Tue, Apr 4, 2017 at 2:15 PM, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Mon, Apr 3, 2017 at 7:07 PM, Tim Uckun <timuckun@gmail.com> wrote:
I am trying to make postgres tables work like an object hierarchy. As an example I have done this.

​I suspect you are barking up the wrong tree ;)

You are probably better off incorporating something like the "ltree" type to encode the taxonomy.


I haven't had a chance to leverage it myself but the concept it embodies is solid.

David J.