select count(*) from task where week_start_date = '2024-11-11'

UPDATE task 
SET week_start_date = '2024-11-18' 
WHERE week_start_date = '2024-11-11';


CREATE TABLE task_backup_20241119 AS 
SELECT * FROM task;

UPDATE task t
SET week_start_date = tb.week_start_date
FROM task_backup_20241119 tb
WHERE t.store_code = tb.store_code
  AND t.week_start_date <> tb.week_start_date
 AND tb.week_start_date >= '2024-11-11';

TRUNCATE TABLE task;

SELECT column_name
FROM information_schema.columns
WHERE table_name = 'task';


DROP FUNCTION IF EXISTS get_max_week_start_date_by_store_code(text)

CREATE OR REPLACE FUNCTION get_max_week_start_date_by_store_code(store_code_input TEXT)
RETURNS DATE AS $$
DECLARE
    max_week_start_date DATE; -- Variable to hold the maximum date
BEGIN
    -- Retrieve the maximum week_start_date for the given store_code
    SELECT MAX(t.week_start_date) INTO max_week_start_date
    FROM task as t
    WHERE t.store_code = store_code_input;

    -- Return the result
    RETURN max_week_start_date;
END;
$$
 LANGUAGE plpgsql;
 

select get_max_week_start_date_by_store_code('EC06')