Comments (5)
In your example, the json1
parameter has a String
type, which means that it has to be provided as a String, e.g.,
set param_json1='{
"a":1,
"b":2
}'
select foo({json1:String});
Surprisingly to me, it produces an error:
Code: 457. DB::Exception: Value {
"a":1,
"b":2
} cannot be parsed as String for query parameter 'json1' because it isn't parsed completely: only 1 of 24 bytes was parsed: {. (BAD_QUERY_PARAMETER)
from clickhouse.
param_
settings are translated into String type after parsing automatically, so you can use it after as a String in substitution.
However, these parameters must be a literal, Array/Map/Tuple of literals, or a combination of them written in ClickHouse syntax. In ClickHouse double quotes ("
) are used for identifiers and you can't have those inside a literal.
Setting parameters like this is supported:
SET param_json1={
'a':1,
'b':2
};
SELECT {json1:String} AS str, {json1:Map(String, UInt64)} AS map;
┌─str────────────┬─map───────────┐
│ {'a':1, 'b':2} │ {'a':1,'b':2} │
└────────────────┴───────────────┘
If the parameter you are trying to set has some other format then you will have to use String literal. Inside this literal the parameter must be in "escaped" format (https://clickhouse.com/docs/en/interfaces/http#tabs-in-url-parameters).
So in your example it would be:
SET param_json1='{\\n "a":1,\\n "b":2,\\n};'
SELECT {json1:String} AS str;
┌─str─────────────────────┐
│ {
"a":1,
"b":2,
}; │
└─────────────────────────┘
from clickhouse.
@evillique It is ok to require Escaped format in HTTP interface and in command line arguments, because it is the only way to distinguish between a string and NULL.
But when the parameter is provided as an explicit string literal, it is questionable.
from clickhouse.
@evillique It is ok to require Escaped format in HTTP interface and in command line arguments, because it is the only way to distinguish between a string and NULL.
But when the parameter is provided as an explicit string literal, it is questionable.
Thank you for responding my question. Actually I have a very long JSON where strings are double-quoted(because it is standard JSON format). So if I cannot use multi-line string as parameter nor double-quote in JSON, then it would be inconvenient.
from clickhouse.
@evillique It is ok to require Escaped format in HTTP interface and in command line arguments, because it is the only way to distinguish between a string and NULL.
But when the parameter is provided as an explicit string literal, it is questionable.Thank you for responding my question. Actually I have a very long JSON where strings are double-quoted(because it is standard JSON format). So if I cannot use multi-line string as parameter nor double-quote in JSON, then it would be inconvenient.
I have tried more. The RapidJSONParser cannot parse a JSON with single-quoted key, such as {'A':1, 'B':2}. If I use standard JSON format, such as {"A":1, "B":2}, parsing succeeds.
from clickhouse.
Related Issues (20)
- Please order statement subsections alphabetically in the menu
- Terminate called for uncaught exception DB::Exception: Cannot schedule a task: fault injected
- Dictionary loading hangs in case of exception during task scheduling
- Improve replication documentation HOT 3
- Probably a final mistake HOT 9
- Add support of a JOIN condition (t1.a IS NULL AND t2.a IS NULL)
- `zlib deflate failed, output buffer too small` error when writing a Parquet + GZIP file into S3 using the S3 table function HOT 4
- Error in ClickHouse query: Multiple expressions for alias. HOT 4
- Clear mark cache for a part as soon as the part becomes inactive HOT 1
- ClickHouse keeps gracefully shutting down - Running as a Docker service HOT 2
- Why I was able to DROP SETTINGS PROFILE ON CLUSTER on 24.3 only with ACCESS MANAGEMENT, and I am not able to do so on 24.4? HOT 2
- Cached MySQL Dictionary tries to use derived table: Code: 1000, e.code() = 1248 Every derived table must have its own alias HOT 2
- Support of aggregation over sparse columns without conversion HOT 1
- Materialize view doesn't populate columns after join and migration to 24.3.2.23 HOT 6
- Why I am not able to access system.numbers as user with no privileges from 24.4? HOT 3
- Unexpected return type from equals: Grouping sets and predicate pushdown HOT 1
- OPTIMIZE TABLE: When to use it? HOT 6
- session_timezone is not reflected in X-ClickHouse-Timezone HOT 8
- What options exist for storing metadata when using S3 as a primary disk? HOT 2
- Docker container with image of clickhouse/clickhouse-server immediately exits on WSL2 with Ubuntu 24.04 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clickhouse.