Skip to content

Instantly share code, notes, and snippets.

@ichux
Created October 2, 2018 03:15
Show Gist options
  • Select an option

  • Save ichux/9346ec1a720bb655a2ff7a4481a8358a to your computer and use it in GitHub Desktop.

Select an option

Save ichux/9346ec1a720bb655a2ff7a4481a8358a to your computer and use it in GitHub Desktop.
row_to_json to get all the first and last days of the current month
WITH first_day AS (SELECT date_trunc('MONTH', NOW()) :: DATE AS first_date),
last_day AS (SELECT (date_trunc('MONTH', (SELECT * FROM first_day)) + INTERVAL '1 MONTH' -
INTERVAL '1 DAY') :: DATE AS last_date)
SELECT row_to_json(first_last)
FROM (SELECT first_day.*, last_day.*
FROM first_day,
last_day) first_last;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment