Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table alias "tc" does not exist #3729

Open
dingyuanhong opened this issue Nov 28, 2024 · 0 comments
Open

table alias "tc" does not exist #3729

dingyuanhong opened this issue Nov 28, 2024 · 0 comments

Comments

@dingyuanhong
Copy link

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

@dingyuanhong dingyuanhong added the bug Something isn't working label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant