-
Notifications
You must be signed in to change notification settings - Fork 962
Open
Labels
bugSomething isn't workingSomething isn't workingtriageNew issues that hasn't been reviewedNew issues that hasn't been reviewed
Description
Version
1.23.0
What happened?
I have a query using a CTE with a WHERE clause filtering a date range using BETWEEN, and sqlc generated the params struct with duplicate fields for the from and to dates.
const listAuthorsWithCTE = `-- name: ListAuthorsWithCTE :many
WITH page AS (SELECT id FROM authors WHERE authors.created_at BETWEEN ? AND ?)
SELECT authors.id, name, bio, created_at, page.id FROM authors
INNER JOIN page ON page.id = authors.id
ORDER BY name
`
type ListAuthorsWithCTEParams struct {
FromCreatedAt time.Time
FromCreatedAt_2 time.Time
ToCreatedAt time.Time
ToCreatedAt_2 time.Time
}And the database is queried with all of them.
rows, err := q.db.QueryContext(ctx, listAuthorsWithCTE,
arg.FromCreatedAt,
arg.FromCreatedAt_2,
arg.ToCreatedAt,
arg.ToCreatedAt_2,
)
Note that changing the WHERE clause to use >= and < outputs the correct number of parameters.
Relevant log output
No response
Database schema
CREATE TABLE authors (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
bio VARCHAR(255),
created_at DATETIME NOT NULL
);SQL queries
-- name: ListAuthorsWithCTE :many
WITH page AS (SELECT id FROM authors WHERE authors.created_at BETWEEN ? AND ?)
SELECT * FROM authors
INNER JOIN page ON page.id = authors.id
ORDER BY name;Configuration
{
"version": "2",
"sql": [{
"schema": "schema.sql",
"queries": "query.sql",
"engine": "mysql",
"gen": {
"go": {
"out": "db"
}
}
}]
}Playground URL
https://play.sqlc.dev/p/f475a847db9fef33de461eadc8638ca289c85e2cd7ab40df344454ccb721c836
What operating system are you using?
macOS
What database engines are you using?
MySQL
What type of code are you generating?
Go
devforma, AdrienHorgnies and kasaikou
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingtriageNew issues that hasn't been reviewedNew issues that hasn't been reviewed