ClickHouse / ClickHouse/clickhouse-go
JSON vs. NamedValue query parameters
- Dominant language
- Go
- Stars
- 3.3k
- Forks
- 680
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 14
Description
Hello,
we are working with JSON data and calling function such as **jsonMergePatch()**. Example:
`SELECT jsonMergePatch('{"test":' || test_value || '}') FROM some_table WHERE id = ?`
The query has a query parameter. The problem is that this query fails with error described as "expected string value in NamedValue for query parameter". While looking into the code we have discovered that there is some magic regular expression which tries to detect named query arguments in the file [https://github.com/ClickHouse/clickhouse-go/blob/main/query_parameters.go#L30C2-L30C18](https://github.com/ClickHouse/clickhouse-go/blob/main/query_parameters.go#L30C2-L30C18).
`hasQueryParamsRe = regexp.MustCompile("{.+:.+}")`
We found that the regex does not hit when the query is multiline so we managed to run it successfully by putting closing bracket on the next line:
```
SELECT jsonMergePatch('{"test":' || test_value ||
'}') FROM some_table WHERE id = ?
```
We would like to ask you how we should approach? Is it a bug in the regular expression or we shall run the query somehow differently?
_Note that we are not using NamedValue, the query parameter is put to the Query(query, args...) just as a common Go variable._
Thanks.
Contributor guide
Research direction
Start in query_parameters.go around hasQueryParamsRe and trace how JSON braces are distinguished from named query parameters when Query receives positional arguments. Reproduce the multiline jsonMergePatch query and compare it with the working formatting; done means JSON expressions no longer cause incorrect NamedValue handling while genuine named parameters still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100