For the sake of example, there's five columns in a table month:
- month.week1
- month.week2
- month.week3
- month.week4
- month.week5
The number of col is determined by a function
EXTRACT(WEEK FROM NOW()) - EXTRACT(WEEK FROM DATE_TRUNC('month', NOW())) + 1
How can I select the column colX? This is what I have so far
SELECT month.week || (
EXTRACT(WEEK FROM NOW())
- EXTRACT(WEEK FROM DATE_TRUNC('month', NOW())) + 1
)::text
FROM month
But that gives me the error
ERROR: column month.week doesn't exist SQL state: 42703