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

JSON vs. NamedValue query parameters #1489

Open
lcapka opened this issue Feb 5, 2025 · 1 comment
Open

JSON vs. NamedValue query parameters #1489

lcapka opened this issue Feb 5, 2025 · 1 comment
Labels
bug feedback required reporter response needed

Comments

@lcapka
Copy link

lcapka commented Feb 5, 2025

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.

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.

@SpencerTorres
Copy link
Member

Hey! Thanks for submitting this issue. I agree with your findings that this is likely a problem with the regex.

I want to understand this query better so I can reproduce the error and try to find a workaround. Can you provide an anonymized snippet of code as well as the table you're using? Is test_value a column?

@SpencerTorres SpencerTorres added bug feedback required reporter response needed labels Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug feedback required reporter response needed
Projects
None yet
Development

No branches or pull requests

2 participants