As far as I can tell, inserting new columns into referenced tables in
JDB does not work. Consider the following example.



NB. We define jdbpath and make a database

   load 'data/jdb'
   hf=: Open_jdb_ jdbpath
   hd=: Create__hf 'sampledb'
   
NB. We create the first table "one"

   Create__hd 'one';'key int;dat int'
+-+
|4|
+-+
   Insert__hd 'one';< 0 1;10 11
   Reads__hd 'from one'
+---+---+
|key|dat|
+---+---+
|0  |10 |
|1  |11 |
+---+---+
   
NB. We insert a new column of integers, it works fine and by default its
values are 0

   InsertCols__hd 'one';'newcol int'
   ShowCols__hd 'one'
+-----+------+----+------+------+---------+
|table|column|type|unique|parent|parentkey|
+-----+------+----+------+------+---------+
|one  |key   |int |1     |      |         |
|one  |dat   |int |0     |      |         |
|one  |newcol|int |0     |      |         |
+-----+------+----+------+------+---------+
   Read__hd 'newcol from one'
+------+---+
|newcol|0 0|
+------+---+
   
NB. We create another table "two", which references one

   Create__hd 'two';'ref one'
+-+
|5|
+-+
   
NB. We try to insert another column into one, but it fails
   
   InsertCols__hd 'one';'newcol2 int'
   ShowCols__hd 'one'
+-----+-------+----+------+------+---------+
|table|column |type|unique|parent|parentkey|
+-----+-------+----+------+------+---------+
|one  |key    |int |1     |      |         |
|one  |dat    |int |0     |      |         |
|one  |newcol |int |0     |      |         |
|one  |newcol2|int |0     |      |         |
+-----+-------+----+------+------+---------+
   Read__hd 'newcol2 from one'
|101 Invalid column: newcol2: throw
|       throw'101 Invalid column: ',towords(ndx=#Tcls)#boxxopen ind


It makes sense that we can't easily insert unique columns into
referenced tables, since that would change a parentkey in another table,
but why not non-unique columns?
Any ideas?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to