是否可以在 postgreSQL 中将 table A ID 索引到 table B userId?
Is it possible to index table A ID to table B userId in postgreSQL?
是否可以在 postgreSQL 中将 table A ID 索引到 table B userId?
所以我会通过 id 或类似的东西加入 2 tables。
为了更好地解释我的问题,这里以 mongoDB 和 mongoose 为例:
const Billing = new Schema({
account:Number,
user: {
type: Schema.Types.ObjectId,
ref: 'user',
required: true
}
});
// later in the code i can do something like
Billing.findOne().populate('user');
这将在用户计费之间创建虚拟关系。
可以用 postgreSQL 完成类似的事情
我正在使用 sequelize ORM。
听起来你在谈论外键
http://www.postgresql.org/docs/8.3/static/tutorial-fk.html
在你的情况下应该是这样的:
create table B (
userid varchar(80) primary key,
<other fields>
);
create table A (
id varchar(80) references B(userid),
<other fields>
);
类型可以根据需要改变
是否可以在 postgreSQL 中将 table A ID 索引到 table B userId? 所以我会通过 id 或类似的东西加入 2 tables。
为了更好地解释我的问题,这里以 mongoDB 和 mongoose 为例:
const Billing = new Schema({
account:Number,
user: {
type: Schema.Types.ObjectId,
ref: 'user',
required: true
}
});
// later in the code i can do something like
Billing.findOne().populate('user');
这将在用户计费之间创建虚拟关系。
可以用 postgreSQL 完成类似的事情
我正在使用 sequelize ORM。
听起来你在谈论外键 http://www.postgresql.org/docs/8.3/static/tutorial-fk.html
在你的情况下应该是这样的:
create table B (
userid varchar(80) primary key,
<other fields>
);
create table A (
id varchar(80) references B(userid),
<other fields>
);
类型可以根据需要改变