Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTjsB-001vgr-Jj for pgsql-general@arkaria.postgresql.org; Tue, 16 Jul 2024 15:13:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sTjsA-001d8y-9c for pgsql-general@arkaria.postgresql.org; Tue, 16 Jul 2024 15:13:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTjs9-001d8q-IE for pgsql-general@lists.postgresql.org; Tue, 16 Jul 2024 15:13:45 +0000 Received: from fhigh6-smtp.messagingengine.com ([103.168.172.157]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTjs1-002QnB-Sd for pgsql-general@lists.postgresql.org; Tue, 16 Jul 2024 15:13:44 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 556D71148037; Tue, 16 Jul 2024 11:13:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 16 Jul 2024 11:13:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1721142816; x=1721229216; bh=rxVCnYwLxrYVUkpaM28nvzsHLMtSGRaELKYfVP/xABE=; b= VkmNsaJ3EiSC9alg2taAyYzARaR83pMP/5z4t+hw5WNVDLiShGZP8qqI5yRszGpI XflzfG3xyAV/fojig1jXO0dSkh0RB7u53uZa9n3MxU/hr4mgNW6Mzzm9ib1iIKHH cb/2y3a7u9gT4/fVP8+jlWM6AvcaTQk0Ro8A9e8eecCUHs5Jgoj7TRPSRD280Vel I9gD6U4i/NgXjejTpVb0c754AyX/Fjmq0q43FUjnWcb5P8/1YA/l+LB66UxIaU54 Y6YtEveVyafejMscBSRL5epjRJ6r3/2rPM5AzpN46K/cxInA400P556wRYYbyuav x+xbJfwZTW2XUaEjk/jAEQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1721142816; x= 1721229216; bh=rxVCnYwLxrYVUkpaM28nvzsHLMtSGRaELKYfVP/xABE=; b=K 3uIE1gX0O1xE7kMpkui+QKF/v7pBY0KWlqOwMMXQqkwm8snXxeEQyqA2piCKO/Fj DvU9yNwha9DpHAqtB3M/zQWeqmi3ES6gIIODNfhQbp/F6cbHJWny5tuwSIVQZ81M O3RKiZpNfDbgNaq9u9a17CHXEQYzzq1wUgoG6r/Q1uIcNLtmHIbIIMKLeGh9gJ+K ADqEyYTsZPK6xhz9W8bpHHSVu3STCInfCB4/lRiGBfj33ypZrCIxtzeh1R/nLUTz Uns2zOKARSvXwpVECesLXIDVMhk1JwHoHf5smspQV24UMdW1uX3W91fTgdNJr+ZM 19Cq49vUSGqVqO1K6k4Aw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrgeeggdekgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeefgeefieeutdfggfetgefgheekjeehteeileeigfet ieekjedvieeviefgheevtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 16 Jul 2024 11:13:34 -0400 (EDT) Message-ID: <82ff4dac-d8b0-4b8b-aa88-e5d74f624a4d@aklaver.com> Date: Tue, 16 Jul 2024 08:13:34 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Code does Not Read in FY 2025 Data To: Anthony Apollis Cc: pgsql-general@lists.postgresql.org References: <1fd63ee5-a8a3-492e-a38d-82ff21da26b8@aklaver.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/16/24 07:59, Anthony Apollis wrote: > I am using Postgres and SQL Server. Does the query 'fail' on both platforms? > Can you test the data pls. Don't know what I am supposed to see? You will need to provide an explanation of what you want the query to return vs what is currently being returned. Probably easiest to provide a sample of data and what you expect the query to return from that data. Do this inline in your post. FYI, further investigation of the zipped data shows the 2025 data has FY values of NULL which would fail "FY" IS NOT NULL. > > On Tue, 16 Jul 2024 at 16:45, Adrian Klaver > wrote: > > On 7/16/24 05:53, Anthony Apollis wrote: > >  1. The problem is the code below reads only data up until 2024, > >     although the table has been updated with latest data that > contains > >     2025, for some odd reason it is not pulling in or showing > data when > >     filtering for 2025 or even 2024 and later, which should > contain all > >     the latest data. > >  2.   SQL: "SET DATEFIRST 7;-- Holding Period Query > > I don't recognize SET DATEFIRST 7 as Postgres command. > > What database are you running this on? > > Have not gone through the below fully, but this: > > "FY" IS NOT NULL AND "FY" >= 'FY24' > > and this > > WEEK_NUMBER."Date" < CURRENT_DATE > > would seem to be at odds if you want to reach into 2025. > > > > >     SELECT > > > >  3. > > > >     -- Holding Period Query > >     SELECT > >          WEEK_NUMBER."Week Number", > >          WM_GH."Calendar day", > >          WM_GH."Month/Week", > >          WM_GH."Day name", > >          WM_GH."Company", > >          WM_GH."Material Code", > >          WM_GH."Metric", > >          WM_GH."Metric Value" > >     FROM > >          ( > >              SELECT > >                  "Calendar day", > >                  "Month/Week", > >                  "Day name", > >                  "Company", > >                  "Material Code", > >                  "Metric", > >                  "Metric Value" > >              FROM > > > > >  "Prod"."IMETA_Weekly_Metrics_in_Focus_Global_Stock_View_SAP_BW" AS > WM_GH > >              WHERE > >                  WM_GH."Metric Focus" LIKE 'Weekly' > >                  AND WM_GH."Calendar day" <= ( > >                      SELECT MAX(WEEK_NUMBER."Date") AS "MAX DATE" > >                      FROM ( > >                          SELECT > >                              "Date", > >                              "Week number", > >                              COUNT("Date") OVER (PARTITION BY "Week > >     number" ORDER BY "Week number") AS "Number of days", > >                              COUNT("Date") OVER (PARTITION BY "Week > >     number" ORDER BY "Date") AS "Day number in weeks" > >                          FROM ( > >                              SELECT DISTINCT > >                                  "Date", > >                                  EXTRACT(WEEK FROM > WEEK_NUMBER."Date") > >     AS "Week number" > >                              FROM > > > >     "dbo"."IMETA_Calendar_Days_Data_Table_Copy10" AS WEEK_NUMBER > >                              WHERE > >                                  "FY" IS NOT NULL AND "FY" >= 'FY24' > >                          ) AS W_MAX > >                      ) AS WEEK_NUMBER > >                      WHERE > >                          WEEK_NUMBER."Date" < CURRENT_DATE > >                          AND "Number of days" = "Day number in weeks" > >                  ) > >          ) AS WM_GH > >     LEFT OUTER JOIN > >          ( > >              SELECT > >                  * > >              FROM ( > >                  SELECT > >                      "Date", > >                      "Week number", > >                      COUNT("Date") OVER (PARTITION BY "Week number" > >     ORDER BY "Week number") AS "Number of days", > >                      COUNT("Date") OVER (PARTITION BY "Week number" > >     ORDER BY "Date") AS "Day number in weeks" > >                  FROM ( > >                      SELECT DISTINCT > >                          "Date", > >                          EXTRACT(WEEK FROM WEEK_NUMBER."Date") AS > "Week > >     number" > >                      FROM > > > "dbo"."IMETA_Calendar_Days_Data_Table_Copy10" > >     AS WEEK_NUMBER > >                  ) AS W_MAX > >              ) AS WEEK_NUMBER > >              WHERE > >                  WEEK_NUMBER."Date" < CURRENT_DATE > >          ) AS WEEK_NUMBER > >     ON > >          WM_GH."Calendar day" = WEEK_NUMBER."Date" > >     ORDER BY > >          WM_GH."Calendar day" DESC; > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > -- Adrian Klaver adrian.klaver@aklaver.com