Skip to content

Instantly share code, notes, and snippets.

@imidsac
Last active January 29, 2020 10:21
Show Gist options
  • Save imidsac/ae93eafa191fb0ea982f5510a6bf266c to your computer and use it in GitHub Desktop.
Save imidsac/ae93eafa191fb0ea982f5510a6bf266c to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION f_insert_date_series_of_bookingItems(BIGINT, DATE, DATE, CHARACTER VARYING, DECIMAL)
RETURNS INTEGER
LANGUAGE plpgsql
AS $_$DECLARE
r RECORD;
s NUMERIC;
BEGIN
-- s = $2;
FOR r IN SELECT generate_series($2 :: DATE, $3, $4::INTERVAL) :: DATE AS mdate
OFFSET 1
LOOP
INSERT INTO booking_items (booking_id, date_of_dues, amount, created_at, updated_at)
VALUES ($1, r.mdate, $5, now() :: TIMESTAMP WITHOUT TIME ZONE, now() :: TIMESTAMP WITHOUT TIME ZONE);
END LOOP;
RETURN 1;
END;$_$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment