Created
October 2, 2018 03:15
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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