Skip to content

MySQL. Incorrect table alias escaping with " instead of ` #434

Open
@lesichkovm

Description

Describe the bug
Incorrect table alias escaping with " instead of `

To Reproduce

innerq := q.Select("ip_address").Distinct()
q := goqu.Select(goqu.COUNT(goqu.Star()).As("count")).From(innerq)

generates:

SELECT COUNT(*) AS "count" FROM (SELECT DISTINCT `ip_address` FROM `stats_visitor` WHERE ((`created_at` >= '2024-10-25 00:00:00') AND (`created_at` <= '2024-10-25 23:59:59')) ) AS "t1" LIMIT 1

throws:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"t1" LIMIT 1

Expected behavior

SELECT COUNT(*) AS "count" FROM (SELECT DISTINCT `ip_address` FROM `snv_stats_visitor` WHERE ((`created_at` >= '2024-10-25 00:00:00') AND (`created_at` <= '2024-10-25 23:59:59')) ) AS `t1` LIMIT 1

Dialect:

  • postgres
  • [ x] mysql
  • sqlite3

Additional context
Current workaround:

sqlStr = strings.Replace(sqlStr, `AS "t1"`, "AS `t1`", 1)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions