1

I have two sets A and B, set B depends on set A;

set A;
set B{A};

In my database I have two tables - A_Table with primary key a_id and table B_Table with composite key b_id and a_id (foreign key). I tried to read data from B_Table table to set B using this script:

table B_Table IN "ODBC" (ConnectionStr) "B_Table":
   [b ~ b_id, a ~ a_id], B[a] ~ b;

But this script doesn't work. It writes

syntax error
context:  [b ~ b_id, a ~ a_id],  >>> B[ <<< a] ~ b;

How can I read data from a table that has 2 key to a one-dimentional set?

4

1 回答 1

1

我认为您不能使用单个表声明将数据直接读入索引集中,但您可以使用辅助二维集:

set AB dimen 2;
table B_Table IN "ODBC" (ConnectionStr) "B_Table":
   AB <- [a_id, b_id];
read table B_Table;
let{a in A} B[a] := setof{(a, b) in AB} b;

另一种选择是对表声明进行索引A并使用 SQL 语句来选择数据a in A

table B_Table{a in A} IN "ODBC" (ConnectionStr)
  ("SQL=SELECT b_id FROM B_Table WHERE a_id = " & a & ";"):
   B[a] <- [b_id];

或类似的东西。

于 2014-10-12T16:35:49.803 回答