I am faced with a query similar to this:
SELECT *
FROM invoicable_interval i,
LATERAL partition_into_months(i.start_date, i.stop_or_current_date) p;
... where partition_into_months is defined similar to this:
CREATE FUNCTION partition_into_months(start_date DATE, stop_date DATE)
RETURNS TABLE (start_date DATE, stop_date DATE, days INT)
AS $$ ... $$
LANGUAGE sql
IMMUTABLE;
So I am doing a cross join with a variable interval for the secondary table, hence the (redundant) keyword LATERAL.
This works fine with PostgreSQL 9.3.6 and 9.4.2, however, with 9.1.3 I get the following error message:
[42601] ERROR: syntax error at or near "."
Position: 398
The indicated position is the dot in the expression "i.start_date".
How can I rewrite this SQL query in order to port it back to PostgreSQL 9.1.3 ?