我在 SQL 中对电气原理图建模时遇到了一些麻烦。我想捕获的结构是
part ??????????? pin
? ?
part_inst ?????? pin_inst
Run Code Online (Sandbox Code Playgroud)
其中“inst”是“instance”的缩写。
例如,我可能part
将 LM358 运算放大器pin
用作 1OUT、1IN-、1IN+、GND、2IN+、2IN-、2OUT 和 V CC。然后我可能会将这部分放在原理图上,创建 apart_inst
和 8
pin_inst
s。
忽略数据字段,我对模式的最初尝试是
create table parts (
part_id bigserial primary key
);
create table pins (
pin_id bigserial primary key,
part_id bigint not null references parts
);
create table part_insts (
part_inst_id bigserial primary key,
part_id bigint not null references parts
);
create table pin_insts (
pin_inst_id bigserial primary key,
part_inst_id bigint …
Run Code Online (Sandbox Code Playgroud) postgresql foreign-key database-design referential-integrity polymorphic-associations
我正在尝试对电路板上零件的放置进行建模。没有任何有意义的限制,我的基本架构如下所示:
create table part (
part_id bigserial primary key,
name text not null,
width double precision not null,
height double precision not null
);
create table board (
board_id bigserial primary key,
width double precision not null,
height double precision not null
);
create table board_part (
board_id bigint not null references board,
part_id bigint not null references part,
position point not null
);
Run Code Online (Sandbox Code Playgroud)
对于b
和b2
any board_part
s,我想强制执行以下约束:
b
位于黑板上:
box(b.position, …
Run Code Online (Sandbox Code Playgroud)postgresql database-design referential-integrity spatial exclusion-constraint