Skip to content

Tuple comparisons generate invalid code for the MySQL engine #1648

Open

Description

@ryanpbrewster

Version

1.13.0

What happened?

A query like

SELECT * FROM foo WHERE (a, b) < (?, ?)

is valid in MySQL, but sqlc is generating the incorrect code for it. In particular, the query should accept two parameters, but sqlc generates:

func (q *Queries) GetFoos(ctx context.Context) ([]Foo, error) {

The correct code is generated for the Postgresql engine.

I believe that the issue is that convertRowExpr is unimplemented here.

Relevant log output

$ SQLCDEBUG=1 sqlc generate
2022/05/28 13:23:17 dolphin.convert: Unknown node type *ast.RowExpr
2022/05/28 13:23:17 dolphin.convert: Unknown node type *ast.RowExpr
2022/05/28 13:23:17 dolphin.convert: Unknown node type *ast.RowExpr
2022/05/28 13:23:17 dolphin.convert: Unknown node type *ast.RowExpr
2022/05/28 13:23:17 dolphin.convert: Unknown node type *ast.RowExpr
2022/05/28 13:23:17 dolphin.convert: Unknown node type *ast.RowExpr

Database schema

CREATE TABLE foo (a INT NOT NULL, b INT NOT NULL)

SQL queries

-- name: GetFoos :one
SELECT 1 FROM foo WHERE (a, b) < (?, ?);

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "mysql",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

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

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on May 28, 2022
  2. ryanpbrewster commented on Jun 18, 2022

    @ryanpbrewster
    Author

    @kyleconroy I have a fix for this here: #1649

    Are you amenable to incremental approaches like that? If so I think I can very quickly close a bunch of related MySQL issues.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions