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 1qEdga-0006gB-GJ for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jun 2023 22:30:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qEdgY-0002Sf-Pw for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jun 2023 22:30:50 +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 1qEdgY-0002SV-GL for pgsql-hackers@lists.postgresql.org; Wed, 28 Jun 2023 22:30:50 +0000 Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qEdgV-00134V-Of for pgsql-hackers@postgresql.org; Wed, 28 Jun 2023 22:30:49 +0000 X-GND-Sasl: vik@postgresfriends.org X-GND-Sasl: vik@postgresfriends.org Received: by mail.gandi.net (Postfix) with ESMTPSA id 94F9C1BF207; Wed, 28 Jun 2023 22:30:44 +0000 (UTC) Message-ID: Date: Thu, 29 Jun 2023 00:30:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: Row pattern recognition Content-Language: en-US To: Tatsuo Ishii Cc: pgsql-hackers@postgresql.org References: <20230626.100520.2022209340496571373.t-ishii@sranhm.sra.co.jp> <90bff6fa-01b7-cf60-f4f4-3412514a7cd2@postgresfriends.org> <20230628.211700.191321983330956034.t-ishii@sranhm.sra.co.jp> From: Vik Fearing In-Reply-To: <20230628.211700.191321983330956034.t-ishii@sranhm.sra.co.jp> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/28/23 14:17, Tatsuo Ishii wrote: > Small question. > >> This query (with all the defaults made explicit): >> >> SELECT s.company, s.tdate, s.price, >> FIRST_VALUE(s.tdate) OVER w, >> LAST_VALUE(s.tdate) OVER w, >> lowest OVER w >> FROM stock AS s >> WINDOW w AS ( >> PARTITION BY s.company >> ORDER BY s.tdate >> ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING >> EXCLUDE NO OTHERS >> MEASURES >> LAST(DOWN) AS lowest >> AFTER MATCH SKIP PAST LAST ROW >> INITIAL PATTERN (START DOWN+ UP+) >> DEFINE >> START AS TRUE, >> UP AS price > PREV(price), >> DOWN AS price < PREV(price) >> ); > >> LAST(DOWN) AS lowest > > should be "LAST(DOWN.price) AS lowest"? Yes, it should be. And the tdate='07-08-2023' row in the first resultset should have '07-08-2023' and '07-10-2023' as its 4th and 5th columns. Since my brain is doing the processing instead of postgres, I made some human errors. :-) -- Vik Fearing