我在postgresql中尝试了一个到多个关系,但什么也没有。
在这里我的错误尝试
CREATE TABLE person_basic_info (
id INT NOT NULL PRIMARY KEY,
gender VARCHAR (50) NULL,
first_name VARCHAR (150) NULL,
last_name VARCHAR (150) NULL,
email VARCHAR (50) NULL,
political_view_id INT NULL,
cambridge_analytica_psychographics_id INT NULL REFERENCES persons_features (id),
revolution_sympathy int NULL,
iq_level INT NULL
);创建人的特征
CREATE TABLE persons_features (
id INT NOT NULL PRIMARY KEY,
dominate_feature VARCHAR (100) NULL
);
--person_basic_info
insert into person_basic_info(id, gender, first_name, last_name, email, political_view_id, cambridge_analytica_psychographics_id,revolution_sympathy,iq_level) values (1,'Female','Corenda','Garrood','cgarrood0@yellowbook.com',6,2,0,86);
insert into person_basic_info(id,gender, first_name, last_name, email, political_view_id, cambridge_analytica_psychographics_id,revolution_sympathy,iq_level) values (2,'Male','Langston','McMychem','lmcmychem1@theatlantic.com',2,4,0,111);
insert into person_basic_info(id,gender, first_name, last_name, email, political_view_id, cambridge_analytica_psychographics_id,revolution_sympathy,iq_level) values (3,'Female','Robbyn','Imison','rimison2@geocities.com',14,3,1,98);
--persons_features
insert into persons_features (id, dominate_feature) values (1,'Agreeableness');
insert into persons_features (id, dominate_feature) values (2,'Conscientiousness');
insert into persons_features (id, dominate_feature) values (3,'Extraversion');
insert into persons_features (id, dominate_feature) values (4,'Neuroticism');
insert into persons_features (id, dominate_feature) values (5,'Openness');但什么都没有。
你能帮我一下吗?
发布于 2020-09-28 21:37:32
如果您按照正确的顺序执行此查询,则不会出现任何错误。在这种情况下,适当的顺序应该是:
将表persons_features
在这种情况下,这对于许多关系来说并不多,除非person可以拥有多个cambridge_analytica_psychographics_id值。如果是这样的话,您应该创建交叉表,而不是引用persons_features表。
https://stackoverflow.com/questions/64104136
复制相似问题