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

subquery #41

Open
whg001 opened this issue May 6, 2024 · 2 comments
Open

subquery #41

whg001 opened this issue May 6, 2024 · 2 comments

Comments

@whg001
Copy link

whg001 commented May 6, 2024

can not parse some sqls. would you like help me to solve this problem
example
"SELECT *, (SELECT group_concat(inner_url) inner_url FROM t_media_info b WHERE a.id = b.msg_id GROUP BY msg_id) inner_url WHERE f_step = 1 AND business_id IN (6, 3, 4, 8, 9, 12, 14, 15, 38, 39, 5) ORDER BY create_time DESC

@mbaumgartl
Copy link
Collaborator

To fix the issue we would have to make a breaking change, because the parser cannot handle "*" and columns/subselects in one query at the moment.

To workaround the problem you need to replace the "*" by single columns. Maybe a different parser (e.g. node-sql-parser) might handle your query.

@whg001
Copy link
Author

whg001 commented May 8, 2024

Thank for your reply, I fixed this subquery。(I have taken over a project that involves this package. Recently, i need to add some feature to it)

/subquery_clause
  = '(' __ stmt:select_stmt __ ')' {
    stmt.parentheses = true
    return stmt
  }

// (SELECT * FROM `t_mi_partner_interface_privilege`) AS `total`
// t_aa.*
// (SELECT * FROM `t_mi_partner_interface_privilege`) `total`
// f_test aaa
column_list_item
  =
  (KW_ALL / (STAR !ident_start))?{
        return {
            expr: {
              type: 'column_ref',
              column: '*'
            },
            as: null
        }
    }
  / tbl:ident __ DOT __ STAR {
      return {
        expr: {
          type: 'column_ref',
          table: tbl,
          column: '*'
        },
        as: null
      };
    }
  / subquery:subquery_clause __ alias:alias_clause? {
      return { expr: subquery, as: alias || null, column:alias  };
    }
  / e:expr __ alias:alias_clause? {
      return { expr: e, as: alias };
    }

```shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants