vitess-sqlparser icon indicating copy to clipboard operation
vitess-sqlparser copied to clipboard

How can I get the binding query?

Open gywndi opened this issue 4 years ago • 0 comments

Hi, I have some question.

I want to collect and parse queries and make statistics by query pattern. Query patterns should be collected in this form.

## AS-IS
select * from abc where x = 1

## TO-BE
select * from abc where x = ?

As a test, I tried the following code, but a different query came out.

func main() {
	stmt, err := sqlparser.Parse("select * from user_items where user_id=1 order by created_at limit 3 offset 10")
	if err != nil {
		panic(err)
	}
	q := sqlparser.GenerateParsedQuery(stmt).Query
	fmt.Println(q)
}

But, the result is as below.

select * from user_items where user_id = 1 order by created_at asc limit 10, 3

please reply. Thanks. Chan.

gywndi avatar Aug 05 '21 04:08 gywndi