Skip to content

Support for naming hints via sqlc.arg in BETWEEN expressions #2277

Description

@dnwe

What do you want to change?

Currently if you use a BETWEEN expression such as SELECT id, name, date FROM events WHERE date BETWEEN ? AND ?; then sqlc simply names the struct fields as Date and Date_2 a'la:

type GetEventByDateParams struct {
	Date   sql.NullTime
	Date_2 sql.NullTime
}

It would be great if naming hints could be passed to sqlc as-in LIKE expressions so you could put SELECT id, name, date FROM events WHERE date BETWEEN sqlc.arg(from_date) AND sqlc.arg(to_date); and that would result in the generated struct fields being FromDate and ToDate. At the moment if you attempt to do that it breaks the parser and the Params struct is omitted entirely (playground link)

What database engines need to be changed?

PostgreSQL, MySQL

What programming language backends need to be changed?

Go

Activity

  1. added
    enhancementNew feature or request
    triageNew issues that hasn't been reviewed
    on May 12, 2023
  2. added this to the v1.19.0 milestone on Jun 6, 2023
  3. Jille commented on Jun 24, 2023

    @Jille
    Contributor

    Kyle added this to the milestone, and I'd like to have the next release, so I wrote a PR :P

    The change was small, but finding where to make it was harder :)

    @SnoozeThis #2366

  4. SnoozeThis commented on Jun 24, 2023

    @SnoozeThis

    (https://snoozeth.is/E8ZK_PmKi-g) I will wait until #2366 is merged and then add a comment.

  5. Jille commented on Jun 24, 2023

    @Jille
    Contributor

    I just realized I misread your feature request. I thought you wanted to have better default names than Date and Date_2. However, I made a drive-by fix that fixed reusing the same parameter number for both left and right and that probably fixed your actual request.

    I've added a test case for your request to my PR.

  6. dnwe commented on Jun 26, 2023

    @dnwe
    Author

    @Jille perfect, testing with sqlc from your branch and it is working well, thank you!

    As you mention, actually the "better defaults" behaviour actually satisfies the original bug without even needing the sqlc.arg support, but thanks for enabling that too

    type GetEventByDateParams struct {
    	FromDate time.Time
    	ToDate   time.Time
    }
  7. SnoozeThis commented on Jun 27, 2023

    @SnoozeThis

    Resolved.

  8. added 2 commits that reference this issue on Oct 13, 2025
    73a6a40
    326c02d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions