SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE OR REPLACE FUNCTION calendar_days(calendar_month INT, calendar_year INT) RETURNS SETOF record AS $$ DECLARE day_of_week INT; day_name TEXT; calendar_record record; BEGIN -- Получаем текущую локаль SELECT current_setting('lc_collate') INTO day_name; -- Получаем день недели для первого дня месяца SELECT EXTRACT(DOW FROM DATE(calendar_year, calendar_month, 1)) INTO day_of_week; -- Выводим календарь на семь дней FOR calendar_record IN SELECT day_of_week + i AS n, day_name || ' ' || LPAD(i + 1, 2, ' ') AS calendar FROM generate_series(0, 6) g(i) LOOP RETURN NEXT calendar_record record; END LOOP; END; $$ LANGUAGE plpgsql; SET calendar.year = 2023; SET calendar.month = 4; SELECT * FROM calendar_days(NULLIF(CURRENT_SETTING('calendar.month'), '')::int, NULLIF(CURRENT_SETTING('calendar.year'), '')::int);

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear