Skip to content

table alias "tc" does not exist #3729

Open
@dingyuanhong

Description

@dingyuanhong

Version

1.27.0

What happened?

table alias "tc" does not exist

Relevant log output

table alias "tc" does not exist

Database schema

CREATE TABLE IF NOT EXISTS `user_account` (
    `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `app_id` INT COMMENT '应用id',
    `masked_sign` TINYINT COMMENT '屏蔽标识',
    `deleted_sign` TINYINT COMMENT '删除标识',

    PRIMARY KEY (`id`) USING BTREE
) AUTO_INCREMENT = 1 COMMENT='账号表';

CREATE TABLE IF NOT EXISTS `app`
(
    `id`                        INT          NOT NULL AUTO_INCREMENT,
     `masked_sign`               TINYINT      NOT NULL DEFAULT 1 COMMENT '屏蔽标识:1-未屏蔽,2-屏蔽',
    `deleted_sign`              TINYINT      NOT NULL DEFAULT 1 COMMENT '删除标识:1-未删除,2-删除',
    `parent_app_id`             INT          NOT NULL DEFAULT 0 COMMENT '合并父应用id',
    PRIMARY KEY (`id`) USING BTREE
) AUTO_INCREMENT = 105 COMMENT = '应用信息';

SQL queries

-- name: GetUserAccountAllChildIDsByAppID :many
SELECT tua.id
FROM user_account AS tua
LEFT JOIN (
    SELECT
        ta.id,
        IFNULL(tb.id, ta.id) AS parent_app_id,
        ifnull(tb.masked_sign,ta.masked_sign) AS masked_sign,
        ifnull(tb.deleted_sign,ta.deleted_sign) AS deleted_sign
    FROM app AS ta
    LEFT JOIN app as tb ON ta.parent_app_id = tb.id
    WHERE ta.masked_sign = 1
      AND ta.deleted_sign = 1
) AS tc ON tc.id = tua.app_id
WHERE tc.masked_sign = 1
    AND tc.deleted_sign = 1
    AND tc.parent_app_id = sqlc.arg('app_id');

Configuration

# Code generated by gen.go. DO NOT EDIT.
version: "2"
overrides:
  go:
    rename:
      source_ip: SourceIP
rules:
  - name: mysql-query-too-costly
    message: "Too costly"
    rule: "has(mysql.explain.query_block.cost_info) && double(mysql.explain.query_block.cost_info.query_cost) > 2.0"
sql:
  - name: "User"
    engine: "mysql"
    database:
      uri: "${USER}:${PSWD}@tcp(${HOST}:${PORT})/${DATABASE}?charset=utf8"
    queries:
      - "query.sql"
    schema:
      - "schema.sql"
    gen:
      go:
        package: "userv2"
        out: "output/"
        output_copyfrom_file_name: "copyfrom.go"
        emit_interface: true
        emit_json_tags: true
        emit_db_tags: true
        emit_prepared_queries: true
        emit_exact_table_names: true
        emit_empty_slices: true
        # emit_exported_queries: true
        emit_result_struct_pointers: true
        emit_params_struct_pointers: true
        emit_pointers_for_null_types: true
        emit_enum_valid_method: true
        emit_all_enum_values: true
        #query_parameter_limit: 5
        omit_unused_structs: false
        sql_package: "database/sql"
        sql_driver: "github.com/go-sql-driver/mysql"
    rules:
      - sqlc/db-prepare

Playground URL

No response

What operating system are you using?

Windows

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