sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Tuple comparisons generate invalid code for the MySQL engine

Open ryanpbrewster opened this issue 3 years ago • 1 comments

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

ryanpbrewster avatar May 28 '22 17:05 ryanpbrewster

@kyleconroy I have a fix for this here: https://github.com/kyleconroy/sqlc/pull/1649

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

ryanpbrewster avatar Jun 18 '22 17:06 ryanpbrewster