在此查询中:
update public.dctable
set dc = 1
from (
select d.*,
min(time) over (partition by prod, customer, city, num) as mintime,
row_number() over (partition by prod, customer, city, num order by
time) as seqnum
from public.dctable d
) dclk
where dclk.seqnum <> 1
我收到错误:
错误:XX000:目标表必须是等值连词谓词的一部分
看不到我错过的东西。只需要设置dc = 1,其中时间&gt; mintime和seqnum&lt;&gt; 1.
有什么想法吗?
谢谢!
答案 0 :(得分:0)
您需要将源表连接到from表,如此
DF
答案 1 :(得分:0)
我猜测Redshift遵循update
上的Postgres语义。如果是这样的话:
update public.dctable d
set dc = 1
from (select d.*,
min(time) over (partition by prod, customer, city, num) as mintime,
row_number() over (partition by prod, customer, city, num order by
time) as seqnum
from public.dctable d
) d2
where d2.prod = d.prod and d2.customer = d.customer and d2.city = d.city and
d2.num = d.num and d2.mintime < d.time;
我不认为row_number()
对你想做的事情是必要的。
答案 2 :(得分:0)
您收到此错误是因为要更新的主表格未直接加入查询的using
部分中的表格。 where子句必须将更新的表作为谓词的一部分。例如(使您的查询按原样运行):
update public.dctable set dc = 1
from (
select by prod, customer, city, num, min(time) as time
from public.dctable group by 1,2,3,4
) dclk
where dclk.prod = dctable.prod
and dclk.customer =dctable.customer
and dclk.city=dctable.city
and dclk.num=dctable.num
and dclk.time=dctable.time