Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1njTmu-0007tg-Gt for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Apr 2022 22:36:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1njTmr-0004v0-7S for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Apr 2022 22:36:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1njTmq-0004up-VH for pgsql-bugs@lists.postgresql.org; Tue, 26 Apr 2022 22:36:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1njTmn-000875-Qw for pgsql-bugs@lists.postgresql.org; Tue, 26 Apr 2022 22:36:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 23QMZsaM276588; Tue, 26 Apr 2022 18:35:54 -0400 From: Tom Lane To: =?UTF-8?B?TG/Dr2MgUmV2ZXN0?= cc: pgsql-bugs@lists.postgresql.org Subject: Re: lag() default value ignored for some window partition depending on table records count? In-reply-to: References: Comments: In-reply-to =?UTF-8?B?TG/Dr2MgUmV2ZXN0?= message dated "Wed, 27 Apr 2022 00:25:36 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <276586.1651012554.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 26 Apr 2022 18:35:54 -0400 Message-ID: <276587.1651012554@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =?UTF-8?B?TG/Dr2MgUmV2ZXN0?= writes: > Long story short: > - We track history data in a partitioned table which boils down to "key > fields + a JSONB data column", the latter being a list of date/numeric > values pair ; > - For every of this date/numeric couple within their "window partitioning", > we need to determine the preceding value, thus the use of lag(, 1, > 0::numeric), since it's relevant for us here to get the very first record > of the partition having "0.00" as its preceding value; > - Except that the "first" row of some partitions gets NULL instead of > 0::numeric as the result of lag(, 1, 0::numeric), while other get > 0::numeric as expected; Hm ... > Attached is the test case database script we've been able to reproduce the > "issue" one hundred percent of the time on, but without the data - even > after compression this weights ∼8.5Mb. Data that I'd happily share would > anyone points me towards the customary way to do it here with such "big" a > file. With no data, this is pretty pointless. Maybe you could make a script to fill the tables with some dummy data that reproduces the problem? regards, tom lane