Skip to content

JSON vs. NamedValue query parameters #1489

Open
@lcapka

Description

@lcapka

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions