Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. select date::date
  2. from generate_series(format('%s-%s-%s', syear, 6, 1)::date,
  3. format('%s-%s-%s', syear + 1, 5, 31)::date,
  4. '1 day'::interval) date;
  5.  
  6. CREATE OR REPLACE FUNCTION myCycle(syear integer)
  7. RETURNS TABLE(sdate date) AS $$
  8. BEGIN
  9. RETURN QUERY
  10. select date::date
  11. from generate_series(format('%s-%s-%s', syear, 6, 1)::date,
  12. format('%s-%s-%s', syear + 1, 5, 31)::date,
  13. '1 day'::interval) date;
  14. END;
  15. $$ LANGUAGE plpgsql;
  16.  
  17. select c.sdate, ot.other_fields
  18. from myCycle(2015) c
  19. inner join other_table ot
  20. on c.sdate = ot.date;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement