Гость
Форумы / IBM DB2, WebSphere, IMS, U2 [игнор отключен] [закрыт для гостей] / typed table (hierarchy). make a children for parent / 4 сообщений из 4, страница 1 из 1
08.06.2004, 11:28
    #32552015
ggv
ggv
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
typed table (hierarchy). make a children for parent
create type parent_t as (p_name varchar(10)) instantiable
ref using bigint
mode db2sql;

create type children_t under parent_t as (ch_name varchar(10)) instantiable
mode db2sql;

create table parent of parent_t (ref is oid user generated, p_name with options not null);
alter table parent add constraint parent_pk primary key (oid);

create table children of children_t under parent inherit select privileges (ch_name with options not null);

Now I fill a parent -
insert into parent values(parent_t(1), 'first p');

The task (and the question) is how to create a children _from_ the existing parent?
Or how to to add the children for existing parent...

to have something like
oid p_name ch_name
--- ------- --------
1 first p first ch

any help greatly appreciated.
...
Рейтинг: 0 / 0
08.06.2004, 14:40
    #32552539
ggv
ggv
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
typed table (hierarchy). make a children for parent
I have read somewhere in the doc that the row from the parent table has to be deleted and then it's possible to insert the row into the children table (with the same as it was in parent attributes).
...
Рейтинг: 0 / 0
08.06.2004, 15:45
    #32552685
Victor Metelitsa
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
typed table (hierarchy). make a children for parent
Как я понимаю, вы пытаетесь вовсе не "to create a children _from_ the existing parent" и не "to add the children for existing parent". На самом деле вы пытаетесь превратить объект класса parent_t в объект класса children_t (реально в DB2 это должно производиться/сопровождаться изменением значения некоей скрытой от пользователя колонки с индикатором класса). По-моему, в DB2 это невозможно. Только удаление/вставка, со всеми вытекающими последствиями.

Вообще, они (ibm'еры) запутывают людей своими parent и child, когда речь идет о суперклассах и подклассах. Можно думать также о внутреннем устройстве так:

create table T(
ref bigint primary key,
type varchar(100), -- на самом деле вроде число, но я взял строку для пущей наглядности
p_name varchar(10),
ch_name varchar(10)
);

и теперь

create view parent as select
ref, p_name
from T
where type in ('parent', 'child')
;

create view child as select
ref, p_name, ch_name
from T
where type in ('child')
;

create trigger parent_ui instead of insert on parent
... insert into T(ref, type, p_name) values (new.ref, 'parent', new.p_name)

create trigger child_ui instead of insert on child
... insert into T(ref, type, p_name, ch_name) values (new.ref, 'child', new.p_name, new.ch_name)

Поэтому ваше "добавление" (то есть мутация) внутри должна выглядеть как
update T set type='child', ch_name=? where ref=?
...
Рейтинг: 0 / 0
08.06.2004, 21:54
    #32553250
ggv
ggv
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
typed table (hierarchy). make a children for parent
Thanks for the complete explanation.
Yes, it's impossible, the single way only is to delete/insert.
...
Рейтинг: 0 / 0
Форумы / IBM DB2, WebSphere, IMS, U2 [игнор отключен] [закрыт для гостей] / typed table (hierarchy). make a children for parent / 4 сообщений из 4, страница 1 из 1
Целевая тема:
Создать новую тему:
Автор:
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]