多对多,其中行映射到整个表?

Many to Many, where rows are mapped to entire tables?

我正在数据库中存储高频财务数据。我想创建一个 table,其中每个金融合约都映射到具有时间序列数据的 tables。

换句话说,我不想指向另一个 table 中的(许多)特定行,而是指向许多整个 table。示例:

Contract A - table "A_January2021_data"
Contract B - table "B_February2018_data"
Contract C - table "C_May1994_data"
Contract C - table "C_October2000_data"

我想稍后使用那个 table 从相关的 table 中提取时间序列数据,即对于合同 C,从 table 中获取所有数据 C_May1994_data , C_October2000_data.

惯用的 SQL 有可能吗?同样重要的是,这是个好主意吗?

这是个好主意吗?:我认为不是。

我建议使用单个 table 来存储时间序列数据,并推荐使用参考 table 来存储合同。然后,您可以 link 通过外键约束将两个 table 放在一起。

create table contracts (
    contract_id serial primary key,
    -- other contract master data here
);

create table data_series (
    date_series_id serial primary key,
    ts timestamp not null,
    contract_id int references contracts(contract_id),
    -- other time series here
);

通过向数据 table 添加整数列获得的开销相当小,并且它使您的架构更容易操作,而不是为每个合同创建 table(这可能会强制你在以后的某个时候使用动态 SQL)。