sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.51k stars 810 forks source link

Unable to generate for query using `generate_series` with new Postgres 16 syntax #3690

Closed jchen42703 closed 2 weeks ago

jchen42703 commented 2 weeks ago

Version

1.27.0

What happened?

Postgres 16 added a function overload to generate_series with a 4th function arg generate_series ( start timestamp with time zone, stop timestamp with time zone, step interval [, timezone text ] ) → setof timestamp with time zone, but it seems to not be recognized by the catalog during sqlc vet and fails.

When I don't set the 4th arg, it runs, but we need the 4th argument (the timezone) to get correct data. The query runs correctly in Postgres 16.4.

Relevant log output

sqlc generate failed.
# package 
query.sql:3:12: function generate_series(unknown, unknown, unknown, unknown) does not exist

Database schema

N/A

SQL queries

WITH day_sequence AS (
    SELECT generate_series(
            '2022-11-06T04:00:00Z'::TIMESTAMPTZ,
            '2023-11-07T04:59:59.999Z'::TIMESTAMPTZ,
            '1 day'::interval,
            'America/New_York'
        )::TIMESTAMPTZ AS date_value
),
day_groups AS (
    SELECT date_value AS calculation_timespan_start,
        (date_value + INTERVAL '1 day')::TIMESTAMPTZ AS calculation_timespan_end
    FROM day_sequence
)
SELECT calculation_timespan_start,
    calculation_timespan_end
FROM day_groups;

Configuration

See playground link.

Playground URL

https://play.sqlc.dev/p/bd0afb4d9f2671446963689a55ff16bd730a7c4ed17f987d00c69772f2cd54af

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

jchen42703 commented 2 weeks ago

For those who ran into a similar issue, it's fixed by setting the database parameter in the sqlc.yaml:

https://docs.sqlc.dev/en/stable/howto/vet.html

:)