table inheritance question
Posted in 2004
Topics: General Discussion
HELP !!!!! How does one insert a value into a subtable if the supertable entry already exists. I have tried looking at the IBM manuals but they only give info on the supertables
Hi, I'm not sure what you mean by sub and super table, but if you are talking about foreign key relationships... you could disable constraints, triggers, whatever is in your way regarding those tables for a brief moment, then insert your record. You would need to manually evaluate all the relationships for that record before inserting it so you don't break anything. enable constraints,triggers,etc after you fix it. If you were to do that, for safety, it would be best to do with no other users in the system. and of course, TEST it somewhere before doing in production. Norma Jean -----Original Message----- From: mojapelo@netscape.net [mailto:mojapelo@netscape.net] Sent: Saturday, January 24, 2004 7:50 AM To: ids@iiug.org; forum.subscriber@iiug.org Subject: table inheritance question [2486] HELP !!!!! How does one insert a value into a subtable if the supertable entry already exists. I have tried looking at the IBM manuals but they only give info on the supertables ----------------------------------------- ============================================================ The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any reproduction, dissemination or distribution of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. Tellabs ============================================================
--0__=08BBE4B4DF8539628f9e8a93df938690918c08BBE4B4DF853962
Content-type: multipart/alternative;
Boundary="1__=08BBE4B4DF8539628f9e8a93df938690918c08BBE4B4DF853962"
--1__=08BBE4B4DF8539628f9e8a93df938690918c08BBE4B4DF853962
Content-type: text/plain; charset=US-ASCII
Hi
you can just insert into the subtable directly, even if the supertable and
subtable have identical shapes, for example
> create row type type1 (a int);
Row type created.
> create table tab1 of type type1;Table created.
> create row type type2 under type1;
Row type created.
> create table tab2 of type type2 under tab1;Table created.
> insert into tab1 values (1);1 row(s) inserted.
> insert into tab2 values (1);1 row(s) inserted.
> select * from tab1;
a
1
1
2 row(s) retrieved.
thanks. davis.
"MMUTLANYNE ...."
<mojapelo@netscap To: ids@iiug.org
e.net> cc:
Sent by: Subject: table inheritance question [2486]
forum.subscriber@
iiug.org
01/24/2004 05:50
AM
HELP !!!!!
How does one insert a value into a subtable if the supertable entry already
exists.
I have tried looking at the IBM manuals but they only give info on the
supertables
--1__=08BBE4B4DF8539628f9e8a93df938690918c08BBE4B4DF853962
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline
<html><body>
<p>Hi<br>
<br>
you can just insert into the subtable directly, even if the supertable and
subtable have identical shapes, for example<br>
<br>
> create row type type1 (a int);<br>
Row type created.<br>
<br>
> create table tab1 of type type1;<br>
Table created.<br>
<br>
> create row type type2 under type1;<br>
Row type created.<br>
<br>
> create table tab2 of type type2 under tab1;<br>
Table created.<br>
<br>
> insert into tab1 values (1);<br>
1 row(s) inserted.<br>
<br>
> insert into tab2 values (1);<br>
1 row(s) inserted.<br>
<br>
> select * from tab1;<br>
<br>
<br>
a <br>
<br>
1<br>
1<br>
<br>
2 row(s) retrieved.<br>
<br>
thanks. davis.<br>
<br>
<br>
<img src="cid:10__=08BBE4B4DF8539628f9e8a93df938@us.ibm.com" width="16"
height="16" alt="Inactive hide details for "MMUTLANYNE ...."
<mojapelo@netscape.net>">"MMUTLANYNE ...."
<mojapelo@netscape.net><br>
<br>
<br>
<table V5DOTBL=true width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td width="1%"><img
src="cid:20__=08BBE4B4DF8539628f9e8a93df938@us.ibm.com" border="0" height="1"
width="72" alt=""><br>
</td><td
style="background-image:url(cid:30__=08BBE4B4DF8539628f9e8a93df938@us.ibm.com);
background-repeat: no-repeat; " width="1%"><img
src="cid:20__=08BBE4B4DF8539628f9e8a93df938@us.ibm.com" border="0" height="1"
width="225" alt=""><br>
<ul>
<ul>
<ul>
<ul><b><font size="2">"MMUTLANYNE ...."
<mojapelo@netscape.net></font></b><br>
<font size="2">Sent by: forum.subscriber@iiug.org</font>
<p><font size="2">01/24/2004 05:50 AM</font></ul>
</ul>
</ul>
</ul>
</td><td width="100%"><img
src="cid:20__=08BBE4B4DF8539628f9e8a93df938@us.ibm.com" border="0" height="1"
width="1" alt=""><br>
<font size="1" face="Arial"> </font><br>
<font size="2"> To: </font><font size="2">ids@iiug.org</font><br>
<font size="2"> cc: </font><br>
<font size="2"> Subject: </font><font size="2">table inheritance question
[2486]</font></td></tr>
</table>
<br>
<br>
<tt>HELP !!!!!<br>
How does one insert a value into a subtable if the supertable entry already
exists.<br>
<br>
I have tried looking at the IBM manuals but they only give info on the
supertables<br>
<br>
<br>
<br>
</tt>
</body></html>
--1__=08BBE4B4DF8539628f9e8a93df938690918c08BBE4B4DF853962--
--0__=08BBE4B4DF8539628f9e8a93df938690918c08BBE4B4DF853962
Content-type: image/gif;
name="graycol.gif"
Content-Disposition: inline; filename="graycol.gif"
Content-ID: <10__=08BBE4B4DF8539628f9e8a93df938@us.ibm.com>
Content-transfer-encoding: base64
R0lGODlhEAAQAKECAMzMzAAAAP///wAAACH5BAEAAAIALAAAAAAQABAAAAIXlI+py+0PopwxUbpu
ZRfKZ2zgSJbmSRYAIf4fT3B0aW1pemVkIGJ5IFVsZWFkIFNtYXJ0U2F2ZXIhAAA7
--0__=08BBE4B4DF8539628f9e8a93df938690918c08BBE4B4DF853962
Content-type: image/gif;
name="ecblank.gif"
Content-Disposition: inline; filename="ecblank.gif"
Content-ID: <20__=08BBE4B4DF8539628f9e8a93df938@us.ibm.com>
Content-transfer-encoding: base64
R0lGODlhEAABAIAAAAAAAP///yH5BAEAAAEALAAAAAAQAAEAAAIEjI8ZBQA7
--0__=08BBE4B4DF8539628f9e8a93df938690918c08BBE4B4DF853962
Content-type: image/gif;
name="pic15717.gif"
Content-Disposition: inline; filename="pic15717.gif"
Content-ID: <30__=08BBE4B4DF8539628f9e8a93df938@us.ibm.com>
Content-transfer-encoding: base64
R0lGODlhWABDALP/AAAAAK04Qf79/o+Gm7WuwlNObwoJFCsoSMDAwGFsmIuezf///wAAAAAAAAAA
AAAAACH5BAEAAAgALAAAAABYAEMAQAT/EMlJq704682770RiFMRinqggEUNSHIchG0BCfHhOjAuh
EDeUqTASLCbBhQrhG7xis2j0lssNDopE4jfIJhDaggI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EFJeGrxUZy8dB8gmAXI/sPvH
ESfCwVt5hTgYiqQqtdRNHQIU1PJ33ZqmzgE90OwLaoJcnMop1WiMmgkPHQRIrwgFuNV90A3doNKT
mrKIN07AnGcI9BQjhCBN4RfA1qIZnMqorJCogKfGQnxSCDilTVIA0yl5ciTovgLuBDKFUDE9aQcw
9SA+rjSNf9/M1gxrj6VwDTS0IUSElMzBfsj0NFXR2kwsV1A5IF1grLgLL/r1R40BZEnuBWgmQEyb
jqRwSAt6bqMCOFkvKFN2GPPkUzIm/SCF8z8pVzpbjVnMsy0vOr1hw3SaSRUhpY09v0z0J1FnwzPl
fmh+xl4WtR0zGu24I4KbMQm3lnVu2oNWxI9W/lcyzA+mCKF4DBikxb/+UWtOGRiFP8qEwAayIgIA
Ow==
--0__=08BBE4B4DF8539628f9e8a93df938690918c08BBE4B4DF853962--
--0__=08BBE4B9DF95E16D8f9e8a93df938690918c08BBE4B9DF95E16D
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: quoted-printable
MMUTLANYNE <mojapelo@netscape.net> asked:
>HELP !!!!!
>How does one insert a value into a subtable if the supertable entry
already
>exists.
>
>I have tried looking at the IBM manuals but they only give info on the=
>supertables
Davis Kwong said:
>you can just insert into the subtable directly, even if the supertable=
and
>subtable have identical shapes, for example
>
>> create row type type1 (a int);
>Row type created.
>
>> create table tab1 of type type1;>Table created.
>
>> create row type type2 under type1;
>Row type created.
>
>> create table tab2 of type type2 under tab1;>Table created.
>
>> insert into tab1 values (1);>1 row(s) inserted.
>
>> insert into tab2 values (1);>1 row(s) inserted.
>
>> select * from tab1;>
> a
>
> 1
> 1
>
>2 row(s) retrieved.
I suspect that MMUTLANYNE has a primary key on the super-table that
prevents duplicate entries.
I also suspect that the answer is that you have to do a combination of
DELETE from super-table and INSERT into sub-table - in a transaction, o=f
course. For a single row case - satisfying the criterion WHERE a =3D 1=
, one
might perhaps do:
BEGIN WORK;
SELECT FROM tab1 WHERE a =3D 1 INTO TEMP x;
DELETE FROM tab1 WHERE a =3D 1;
INSERT INTO tab2 SELECT * FROM x;COMMIT WORK;
Handling more general cases where the sub-type table has more columns t=
han
the super-type would be harder - you'd probably start by selecting noth=
ing
from the sub-table into a temp table (to get the right target table sha=
pe,
then do the cross-load from the super-type table specifying the column
values. At some point, you'd have to set the subtable columns to
appropriate non-null values. Then, finally, you could cross-load from =
the
temp table and commit (or rollback on an error).
In passing, I note that the IDS 9.40 Informix Guide to SQL: Syntax manu=
al
implies (p2-255 of ct1sqna.pdf) that the OF TYPE clause can use..
OF TYPE rowtype ( field-definition-comma-list ,
multi-column-constraint-comma-list ) UNDER supertable
It doesn't say that the field-definition-comma-list (my name for a
non-empty comma-separated list of 'field definitions') can be empty, no=
r
that the constraint list can be empty, which is slightly puzzling, but =
more
significantly, I've been unable to get any notation that includes the
mandatory parentheses - which can nominally be empty - to work. I've t=
ried
a number of semi-plausible constructs, and none of them worked. I fear=
this is a documentation error.
CREATE TABLE t1 OF TYPE type1; -- Non-controversial
CREATE TABLE t2 OF TYPE type2 UNDER t1; -- Worked - but manual says t=his
should fail (empty parens are necessary before UNDER)
CREATE TABLE t3 OF TYPE type2 ( ) UNDER t2; -- Failed - but manual =says
the parens should be necessary
I tried a fairly large number of (c INT NOT NULL) and (c INT NOT NULL,
UNIQUE(a, c)) type constructs where the empty parentheses are, and ever=
y
one which tries to add columns comes back -201 syntax error with IDS
9.40.UC1. As Davis pointed out to me when we chatted about this, it
doesn't make sense for a subtable to be able to define additional field=
s.
That subtable is of type 'rowtype' which means that the subtable's colu=
mn
definition is a one-to-one match to the rowtype's field definition. Y=
ou
can (optionally) add a unique constraint, for example. So, the parenth=
eses
in the syntax diagram should be optional (not mandatory), and the
'field-definition-comma-list' should not be part of the syntax. I've
reported this to the docinf@us.ibm.com mailing list, so the documentati=
on
will be updated in due course.
--
Jonathan Leffler (jleffler@us.ibm.com)
STSM, Informix Database Engineering, IBM Data Management
4100 Bohannon Drive, Menlo Park, CA 94025
Tel: +1 650-926-6921 Tie-Line: 630-6921
"I don't suffer from insanity; I enjoy every minute of it!"=
--0__=08BBE4B9DF95E16D8f9e8a93df938690918c08BBE4B9DF95E16D
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline
Content-transfer-encoding: quoted-printable
<html><body>
<p><tt>MMUTLANYNE <mojapelo@netscape.net> asked:<br>
>HELP !!!!!<br>
>How does one insert a value into a subtable if the supertable entry=
already<br>
>exists.<br>
><br>
>I have tried looking at the IBM manuals but they only give info on =
the<br>
>supertables</tt><br>
<br>
<br>
Davis Kwong said:<br>
<tt><br>
>you can just insert into the subtable directly, even if the superta=
ble and<br>
>subtable have identical shapes, for example<br>
><br>
>> create row type type1 (a int);<br>
>Row type created.<br>
><br>
>> create table tab1 of type type1;<br>
>Table created.<br>
><br>
>> create row type type2 under type1;<br>
>Row type created.<br>
><br>
>> create table tab2 of type type2 under tab1;<br>
>Table created.<br>
><br>
>> insert into tab1 values (1);<br>
>1 row(s) inserted.<br>
><br>
>> insert into tab2 values (1);<br>
>1 row(s) inserted.<br>
><br>
>> select * from tab1;<br>
><br>
> a<br>
><br>
> 1<br>
> 1<br>
><br>
>2 row(s) retrieved.<br>
</tt><br>
I suspect that <tt>MMUTLANYNE</tt> has a primary key on the super-table=
that prevents duplicate entries.<br>
<br>
I also suspect that the answer is that you have to do a combination of =
DELETE from super-table and INSERT into sub-table - in a transaction, o=f course. For a single row case - satisfying the criterion WHERE a =3D=
1, one might perhaps do:
<ul><br>
BEGIN WORK;<br>
SELECT FROM tab1 WHERE a =3D 1 INTO TEMP x;<br>
DELETE FROM tab1 WHERE a =3D 1;<br>
INSERT INTO tab2 SELECT * FROM x;<br>COMMIT WORK;<br>
</ul>
Handling more general cases where the sub-type table has more columns t=
han the super-type would be harder - you'd probably start by selecting =
nothing from the sub-table into a temp table (to get the right target t=
able shape, then do the cross-load from the super-type table specifying=
the column values. At some point, you'd have to set the subtable colu=
mns to appropriate non-null values. Then, finally, you could cross-loa=
d from the temp table and commit (or rollback on an error).<br>
<br>
In passing, I note that the IDS 9.40 Informix Guide to SQL: Syntax manu=
al implies (p2-255 of ct1sqna.pdf) that the OF TYPE clause can use..<br=
>
<ul>OF TYPE rowtype ( field-definition-comma-list , multi-column-constr=
aint-comma-list ) UNDER supertable</ul>
<br>
It doesn't say that the field-definition-comma-list (my name for a non-=
empty comma-separated list of 'field definitions') can be empty, nor th=
at the constraint list can be empty, which i