Skip to content

MySQL does not support the having parameter #1795

@xiaozefeng

Description

@xiaozefeng

Version

Other

What happened?

When I define a statement with the having keyword and a parameter placeholder, but no corresponding parameter is generated.

Example:

select content as content, count(*) as num
from tb_art_comment
where art_id = ?
  and art_type = ?
group by content having num > ?

Generated code with params:

type GetCommentByArtIdParams struct {
	ArtID   int64
	ArtType art.Type
}

I expect the parameters to be having generating parameters

Relevant log output

nothing

Database schema

CREATE TABLE `tb_art_comment`
(
    `id`          bigint(20)                       NOT NULL AUTO_INCREMENT,
    `create_time` timestamp                        NULL DEFAULT NULL,
    `update_time` timestamp                        NULL DEFAULT NULL,
    `content`     varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `art_id`      bigint(20)                       NOT NULL,
    `art_type`    bigint(20)                       NOT NULL,
    `user_id`     bigint(20)                       NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 26
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;

CREATE TABLE `tb_art_like_record`
(
    `id`          bigint(20) NOT NULL AUTO_INCREMENT,
    `create_time` timestamp  NULL DEFAULT NULL,
    `update_time` timestamp  NULL DEFAULT NULL,
    `user_id`     bigint(20) NOT NULL,
    `art_id`      bigint(20)      DEFAULT NULL,
    `type`        bigint(20) NOT NULL,
    `status`      bigint(20) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 21
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;

CREATE TABLE `tb_book`
(
    `id`          bigint(20)                       NOT NULL AUTO_INCREMENT,
    `create_time` timestamp                        NULL DEFAULT NULL,
    `update_time` timestamp                        NULL DEFAULT NULL,
    `authors`     json                             NOT NULL,
    `binding`     varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `image`       varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `large`       varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `isbn`        varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `pages`       varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `price`       bigint(20)                       NOT NULL,
    `pub_date`    timestamp                        NULL DEFAULT NULL,
    `publisher`   varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `subtitle`    varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `title`       varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `summery`     longtext COLLATE utf8mb4_bin     NOT NULL,
    `translator`  json                             NOT NULL,
    `category_id` bigint(20)                            DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `tb_book_tb_book_category_books` (`category_id`),
    CONSTRAINT `tb_book_tb_book_category_books` FOREIGN KEY (`category_id`) REFERENCES `tb_book_category` (`id`) ON DELETE SET NULL
) ENGINE = InnoDB
  AUTO_INCREMENT = 13
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;

CREATE TABLE `tb_book_category`
(
    `id`          bigint(20)                       NOT NULL AUTO_INCREMENT,
    `create_time` timestamp                        NULL     DEFAULT NULL,
    `update_time` timestamp                        NULL     DEFAULT NULL,
    `name`        varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `parent_id`   bigint(20)                                DEFAULT NULL,
    `sort`        bigint(20)                       NOT NULL DEFAULT '999',
    `icon`        varchar(255) COLLATE utf8mb4_bin          DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;

CREATE TABLE `tb_classic`
(
    `id`          bigint(20)                       NOT NULL AUTO_INCREMENT,
    `create_time` timestamp                        NULL DEFAULT NULL,
    `update_time` timestamp                        NULL DEFAULT NULL,
    `content`     varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `image`       varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `index`       bigint(20)                       NOT NULL,
    `pubdate`     timestamp                        NULL DEFAULT NULL,
    `title`       varchar(255) COLLATE utf8mb4_bin NOT NULL,
    `type`        bigint(20)                       NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 3
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;

CREATE TABLE `tb_search_record`
(
    `id`          bigint(20)                      NOT NULL AUTO_INCREMENT,
    `create_time` timestamp                       NULL DEFAULT NULL,
    `update_time` timestamp                       NULL DEFAULT NULL,
    `keyword`     varchar(20) COLLATE utf8mb4_bin NOT NULL,
    `user_id`     bigint(20)                           DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 49
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;

CREATE TABLE `tb_user`
(
    `id`          bigint(20) NOT NULL AUTO_INCREMENT,
    `create_time` timestamp  NULL                  DEFAULT NULL,
    `update_time` timestamp  NULL                  DEFAULT NULL,
    `name`        varchar(25) COLLATE utf8mb4_bin  DEFAULT NULL,
    `nick_name`   varchar(25) COLLATE utf8mb4_bin  DEFAULT NULL,
    `mobile`      varchar(11) COLLATE utf8mb4_bin  DEFAULT NULL,
    `passwd`      varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
    `avatar`      varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
    `sex`         bigint(20) NOT NULL              DEFAULT '0',
    `status`      bigint(20) NOT NULL              DEFAULT '1',
    `openid`      varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 4
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;

SQL queries

-- name: GetCommentByArtId :many
select content as content, count(*) as num
from tb_art_comment
where art_id = ?
  and art_type = ?
group by content having num > sqlc.arg(num)
limit ?,?

Configuration

version: 1
packages:
  - path: "sqlc"
    name: "sqlc"
    engine: "mysql"
    schema: "schema.sql"
    queries: "query.sql"
    emit_prepared_queries: true
    emit_empty_slices: true
    #    emit_json_tags: true
    emit_result_struct_pointers: true
    emit_params_struct_pointers: true
#    json_tags_case_style: "camel"
rename:
  tb_art_comment: "ArtComment"
  tb_art_like_record: "ArtLikeRecord"
  tb_book: "Book"
  tb_book_category: "BookCategory"
  tb_classic: "Classic"
  tb_search_record: "SearchRecord"
  tb_user: "User"
overrides:
  - column: "tb_art_like_record.type"
    go_type: "blink/api/enum/art.Type"
  - column: "tb_classic.type"
    go_type: "blink/api/enum/art.Type"
  - column: "tb_art_comment.art_type"
    go_type: "blink/api/enum/art.Type"

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

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