Skip to content

[mysql] Not support where id in (?) #706

Closed

Description

@dotNetDR

schema.sql

CREATE TABLE authors (
          id   bigint NOT NULL AUTO_INCREMENT,
          name varchar(100)      NOT NULL,
          PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

query.sql

/* name: ListAuthorsByIDs :many */
SELECT * FROM authors
WHERE id IN (?);

generate code:
query.sql.go

// Code generated by sqlc. DO NOT EDIT.
// source: query.sql

package dao

import (
	"context"
)

const listAuthorsByIDs = `-- name: ListAuthorsByIDs :many
select id, name from authors where id in (?)
`

func (q *Queries) ListAuthorsByIDs(ctx context.Context, id int) ([]Author, error) {
	rows, err := q.db.QueryContext(ctx, listAuthorsByIDs, id)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Author
	for rows.Next() {
		var i Author
		if err := rows.Scan(&i.ID, &i.Name); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

issues 77 commit is wrong

sqlc version
v1.3.0, v1.5.0

Activity

  1. kyleconroy commented on Sep 8, 2020

    @kyleconroy
    Collaborator

    Sorry for the confusing documentation here. MySQL does not support arrays, so the generated code is correct. The ability to pass slices to MySQL is currently not supported by sqlc. However, we're working on adding support. Please see #695 for a discussion on supporting passing slices to queries.

  2. changed the title [-][mysql] Not support where in id in (?)[/-] [+][mysql] Not support where id in (?)[/+] on Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    📚 mysqlduplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions