On Mon, Aug 21, 2023 at 3:07 PM Anthony Apollis <anthony.apollis@xxxxxxxxx> wrote: > > Please review my code and make recommendations where needed. I have this code: > ``` > NUMBER OF LOOPS FOR POSTGRESQL ETL: > SELECT > CASE > WHEN (((EXTRACT(DAY FROM > ((CASE > WHEN > (SELECT DISTINCT "CALDAY" FROM “system”.”IMETA_ZACTPRIC1_Cust_Pricing_TA_BW” AS WEEK_NUMBER > WHERE > WEEK_NUMBER."CALDAY" = (SELECT MAX(DISTINCT "CALDAY") AS "Calendar day" FROM “system”.”IMETA_ZACTPRIC1_Cust_Pricing_TA_BW” AS WEEK_NUMBER)) IS NULL THEN '2020-07-01' > ELSE > (SELECT DISTINCT "CALDAY" FROM “system”.”IMETA_ZACTPRIC1_Cust_Pricing_TA_BW” AS WEEK_NUMBER > WHERE > WEEK_NUMBER."CALDAY" = (SELECT MAX(DISTINCT "CALDAY") AS "Calendar day" FROM “system”.”IMETA_ZACTPRIC1_Cust_Pricing_TA_BW” AS WEEK_NUMBER)) + interval '1 day' > END))::timestamp - --start date > (CAST(NOW() - INTERVAL '1 day' AS DATE))::timestamp)-1) --end date > * -1)) <= 30 THEN 1 > ELSE > CEIL(((EXTRACT(DAY FROM > ((CASE > WHEN > (SELECT DISTINCT "CALDAY" FROM “system”.”IMETA_ZACTPRIC1_Cust_Pricing_TA_BW” AS WEEK_NUMBER > WHERE > WEEK_NUMBER."CALDAY" = (SELECT MAX(DISTINCT "CALDAY") AS "Calendar day" FROM “system”.”IMETA_ZACTPRIC1_Cust_Pricing_TA_BW” AS WEEK_NUMBER)) IS NULL THEN '2020-07-01' > ELSE > (SELECT DISTINCT "CALDAY" FROM “system”.”IMETA_ZACTPRIC1_Cust_Pricing_TA_BW” AS WEEK_NUMBER > WHERE > WEEK_NUMBER."CALDAY" = (SELECT MAX(DISTINCT "CALDAY") AS "Calendar day" FROM system."IMETA_ZINV_AP1_Invoice_data_TA_BW"" AS WEEK_NUMBER)) + interval '1 day' > END))::timestamp - --start date > (CAST(NOW() - INTERVAL '1 day' AS DATE))::timestamp)-1) --end date > * -1)/30) --30 DAY INTERVALS UNLESS LESS > END > AS "Number of days" > “system”.”IMETA_ZACTPRIC1_Cust_Pricing_TA_BW” seems like some of the characters look like double quotes, but it's maybe not a double quote. wiki: https://en.wikipedia.org/wiki/Quotation_mark.