parser icon indicating copy to clipboard operation
parser copied to clipboard

how to get the table names from BinaryOperationExpr of where clause

Open baichuanyang opened this issue 4 years ago • 2 comments

Question

Hi.

i would like to parse a kind of query like:

select * from a inner join b on a.col1 == b.col1 inner join c on b.col2 == c.col2 where a.col3 = 1 and b.col4 = 5

and i got two *ast.BinaryOperationExpr of the where clause a.col3 = 1 and b.col4 = 5. however, that expression only contained *ast.ColumnNameExpr and *driver.ValueExpr and ignored the *ast.TableSource.

may i know how to get the table names?

thanks

baichuanyang avatar Aug 02 '21 03:08 baichuanyang

you can take a look at type ColumnName

https://github.com/pingcap/parser/blob/94275e813903b69c6e04bd036959d076afa5b89e/ast/expressions.go#L558-L569

lance6716 avatar Aug 03 '21 05:08 lance6716

you can take a look at type ColumnName

https://github.com/pingcap/parser/blob/94275e813903b69c6e04bd036959d076afa5b89e/ast/expressions.go#L558-L569

But this will cause many duplicate ColumnName to appear. Is there any way to reduce duplication?

cjphaha avatar Oct 09 '21 18:10 cjphaha