Skip to content

Wrong variable name generation with named parameter inside OFFSET() function #86

@maxnetyaga

Description

@maxnetyaga
-- name: get_plot_lists :many
WITH grouped_lists AS (
    SELECT
        l.id,
        l.name,
        l.created_at,
        array_agg(p2l.cadastral_number) AS cadastral_numbers
    FROM public.plot_lists AS l
    LEFT JOIN public.land_plot2plot_list AS p2l ON l.id = p2l.plot_list_id
    GROUP BY l.id, l.name
)
SELECT
    gl.name,
    gl.cadastral_numbers,
    (SELECT COUNT(*) FROM public.plot_lists) AS total
FROM grouped_lists gl
ORDER BY gl.created_at
LIMIT @pagination_limit OFFSET (@page - 1) * @pagination_limit;

This sql query gives next python function:

async def get_plot_lists(self, *, -page: Optional[Any], pagination_limit: int) -> AsyncIterator[get_plot_listsRow]:
    result = await self._conn.stream(sqlalchemy.text(GET_PLOT_LISTS), {"p1": -page, "p2": pagination_limit})
    async for row in result:
        yield get_plot_listsRow(
            name=row[0],
            cadastral_numbers=row[1],
            total=row[2],
        )

'page' arg generated with '-' as prefix.

-> % sqlc version
v1.28.0

plugins:
- name: py
wasm:
url: https://downloads.sqlc.dev/plugin/sqlc-gen-python_1.3.0.wasm
sha256: fbedae96b5ecae2380a70fb5b925fd4bff58a6cfb1f3140375d098fbab7b3a3c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions