0

I have some sparse date-related data in Postgres, and I want to extract a report that has a complete date range (even if there is no related data). I want to do the equivalent of a left outer join between a (non-existent) table of all dates in a range, and the data table that I have, i.e.

SELECT temp_dates.date, data_table.data_field
FROM temp_dates
LEFT OUTER JOIN data_table
ON temp_dates.date = data_table.data

My question is - how do I do create the temp table with the full range of dates?

NB I've asked about temp tables as I understand them, however if there is a better way (e.g. joining a table to an array, for instance), then I'd really like to know.

1 Answer 1

2

generate_series on PostgreSQL

get min date from your range then max and generate series

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for this - generate_series is exactly what I was looking for. Unfortunately I'm now getting unexpected results from the join. I will mark this as the answer and then open another question.
Please add an actual solution, not just a "look here for something you will use" link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.