我有一个名为pool_hashrate
的表,其中包含以下列:id
(PK),hashrate
,network_id
(FK),pool_id
(FK)。我想用查询填充它们:
insert into pool_hashrate (
hashrate, network_id, pool_id
)
select
i+i::double precision, i, i
from generate_series(0, 15) AS i;
这些表是通过Hibernate自动生成的。来自pgAdmin的SQL代码片段:
CREATE TABLE public.pool_hashrate
(
id bigint NOT NULL DEFAULT nextval('pool_hashrate_id_seq'::regclass),
hashrate double precision NOT NULL,
network_id bigint NOT NULL,
pool_id bigint NOT NULL,
CONSTRAINT pool_hashrate_pkey PRIMARY KEY (id),
CONSTRAINT fk52n7131wvbi6196idmf1wfb0e FOREIGN KEY (pool_id)
REFERENCES public.pool_hashrate (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT fkjph0cotxu5udghsbbgtpysv66 FOREIGN KEY (network_id)
REFERENCES public.network_hashrate (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.pool_hashrate
OWNER to postgres;
约束可以成为问题吗?在pgAdmin中执行查询时,我收到rows affected -1
消息。
修改
我一直收到错误Null value in column “network_id” violates not-null constraint when adding new item.
为什么null
被添加到那里,如果它应该是i
?
编辑2
事实上,在上述查询之前,我正在运行其他2个查询来填充network_hashrate
& pool_hashrate
。这些查询是:
insert into network_hashrate (
rep_date, hashrate
)
select
current_timestamp - (s.a || ' hour')::interval,
s.a::double precision
from generate_series(0, 15, 1) AS s(a);
insert into pool_def (
name, date_from
)
select
left(md5(random()::text), 10),
current_timestamp - (s.a || ' hour')::interval
from generate_series(0, 15, 1) AS s(a);
所以回答你的问题,是的,我确实在network_hashrate
中有记录。我猜应该没有问题?