From 5d65fc4c576c5200b5a7049c073406568fd7e7ad Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 2 Jun 2020 16:42:36 +0300 Subject: [PATCH] Replace lag function with lead to calculate coin balance deltas --- apps/explorer/lib/explorer/chain/address/coin_balance.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain/address/coin_balance.ex b/apps/explorer/lib/explorer/chain/address/coin_balance.ex index 6c9289e741..8e410e993f 100644 --- a/apps/explorer/lib/explorer/chain/address/coin_balance.ex +++ b/apps/explorer/lib/explorer/chain/address/coin_balance.ex @@ -78,7 +78,7 @@ defmodule Explorer.Chain.Address.CoinBalance do where: not is_nil(cb.value), order_by: [desc: :block_number], limit: ^page_size, - select_merge: %{delta: fragment("coalesce(lag(value, 1) over (order by block_number desc), 0) - value")} + select_merge: %{delta: fragment("value - coalesce(lead(value, 1) over (order by block_number desc), 0)")} ) end