Skip to content

Instantly share code, notes, and snippets.

@imidsac
Last active January 29, 2020 10:21
Show Gist options
  • Select an option

  • Save imidsac/ae93eafa191fb0ea982f5510a6bf266c to your computer and use it in GitHub Desktop.

Select an option

Save imidsac/ae93eafa191fb0ea982f5510a6bf266c to your computer and use it in GitHub Desktop.

Revisions

  1. imidsac renamed this gist Jan 29, 2020. 1 changed file with 0 additions and 0 deletions.
  2. imidsac revised this gist Jan 29, 2020. 2 changed files with 16 additions and 20 deletions.
    20 changes: 0 additions & 20 deletions education.sql
    Original file line number Diff line number Diff line change
    @@ -1,20 +0,0 @@
    CREATE OR REPLACE FUNCTION f_date_series()
    RETURNS INTEGER
    LANGUAGE plpgsql
    AS $_$DECLARE
    r RECORD;
    s NUMERIC;
    BEGIN
    -- s = $2;
    FOR r IN SELECT generate_series(
    (DATE '2020-01-31'),
    (DATE '2021-01-31'),
    INTERVAL '1 month'
    ) :: DATE AS mdate
    LIMIT 12
    LOOP
    INSERT INTO booking_items (booking_id, date_of_dues, amount, created_at, updated_at)
    VALUES (1, r.mdate, 0, '2017-03-17 02:09:30', '2017-03-17 02:09:30');
    END LOOP;
    RETURN 1;
    END;$_$;
    16 changes: 16 additions & 0 deletions f_insert_date_series_of_bookingItems
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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;$_$;
  3. imidsac created this gist Jan 28, 2020.
    20 changes: 20 additions & 0 deletions education.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    CREATE OR REPLACE FUNCTION f_date_series()
    RETURNS INTEGER
    LANGUAGE plpgsql
    AS $_$DECLARE
    r RECORD;
    s NUMERIC;
    BEGIN
    -- s = $2;
    FOR r IN SELECT generate_series(
    (DATE '2020-01-31'),
    (DATE '2021-01-31'),
    INTERVAL '1 month'
    ) :: DATE AS mdate
    LIMIT 12
    LOOP
    INSERT INTO booking_items (booking_id, date_of_dues, amount, created_at, updated_at)
    VALUES (1, r.mdate, 0, '2017-03-17 02:09:30', '2017-03-17 02:09:30');
    END LOOP;
    RETURN 1;
    END;$_$;