我试图使用多个CTE运行一个SQL查询,但得到"ERROR: relation“不存在
这是密码。我做错了什么?
WITH tmp AS (
Select a.tx_id, a.txo_index, a.address,b.tx_in_id from txo as a
inner join txin as b ON (a.tx_id = b.tx_out_id and a.txo_index= b.tx_out_index)
where a.tx_in_id = 0
),
tmp2 AS
(
Select tmp.tx_id,tmp.txo_index,tmp.address,tmp.tx_in_id,b.value as value_next,c.epoch_no as consumed_epoch,c.date as consumed_date from tmp
inner join txo as b ON
tmp.tx_in_id = b.tx_id and
tmp.address = b.address
inner join tx as c ON
tmp.tx_in_id = c.id
)
Update t
SET
t.tx_in_id = tmp2.tx_in_id,
t.value_next = tmp2.value_next,
t.consumed_epoch = tmp2.epoch_no,
t.consumed_date = tmp2.date
FROM txo as t
inner join tmp2 ON
t.tx_id = tmp2.tx_id and t.txo_index = tmp2.txo_index and t.address = tmp2.address
where t.tx_in_id =0发布于 2022-04-12 14:47:52
我认为在postgres中不允许将表作为UPDATE和SET子句中的别名。相反:
WITH tmp AS (
Select a.tx_id, a.txo_index, a.address,b.tx_in_id from txo as a
inner join txin as b ON (a.tx_id = b.tx_out_id and a.txo_index= b.tx_out_index)
where a.tx_in_id = 0
),
tmp2 AS
(
Select tmp.tx_id,tmp.txo_index,tmp.address,tmp.tx_in_id,b.value as value_next,c.epoch_no as consumed_epoch,c.date as consumed_date from tmp
inner join txo as b ON
tmp.tx_in_id = b.tx_id and
tmp.address = b.address
inner join tx as c ON
tmp.tx_in_id = c.id
)
Update txo
SET
tx_in_id = tmp2.tx_in_id,
value_next = tmp2.value_next,
consumed_epoch = tmp2.epoch_no,
consumed_date = tmp2.date
FROM tmp2
WHERE txo.tx_id = tmp2.tx_id
and txo.txo_index = tmp2.txo_index
and txo.address = tmp2.address
and txo.tx_in_id =0https://stackoverflow.com/questions/71844691
复制相似问题