|
typed table (hierarchy). make a children for parent
|
|||
---|---|---|---|
#18+
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. ... |
|||
:
Нравится:
Не нравится:
|
|||
08.06.2004, 11:28 |
|
typed table (hierarchy). make a children for parent
|
|||
---|---|---|---|
#18+
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). ... |
|||
:
Нравится:
Не нравится:
|
|||
08.06.2004, 14:40 |
|
typed table (hierarchy). make a children for parent
|
|||
---|---|---|---|
#18+
Как я понимаю, вы пытаетесь вовсе не "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=? ... |
|||
:
Нравится:
Не нравится:
|
|||
08.06.2004, 15:45 |
|
|
start [/forum/topic.php?fid=43&msg=32552685&tid=1606245]: |
0ms |
get settings: |
7ms |
get forum list: |
14ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
333ms |
get topic data: |
11ms |
get forum data: |
2ms |
get page messages: |
48ms |
get tp. blocked users: |
3ms |
others: | 331ms |
total: | 753ms |
0 / 0 |