You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's an issue when inserting and trying to fetch a tuple array with certain string formatting - in this case parens:
[("key1", "value1"), ("key2", "this is an invalid pair(with some parens) and this, let's see if it works")]
When it is fetched, it comes back as:
[('key1', 'value1'), ('key2', "'this is an invalid pair(with some parens) and thi"), ("let's see if it works'",)]
Which is not a valid tuple - this cannot be reinserted to Clickhouse.
See code below, this is the entire result fetched:
[{'a': [('key1', 'value1'), ('key2', "'this is an invalid pair(with some parens) and thi"), ("let's see if it works'",)]}, {'a': [('key3', 'value3'), ('key4', 'value4')]}, {'a': [('key5', 'value5'), ('key6', 'value6')]}, {'a': [('key7', 'value7'), ('key8', 'value8')]}, {'a': [('key11', ''), ('key12', "''")]}, {'a': [('key9', 'value9'), ('key10', 'value10')]}]
If trying to reinsert this record as is, we get the error:
aiochclient.exceptions.ChClientError: Code: 386. DB::Exception: There is no supertype for types Tuple(String, String), Tuple(String, String), String because some of them are Tuple and some of them are not: While processing [('key1', 'value1'), ('key2', '\'this is an invalid pair(with some parens) and thi'), 'let\'s see if it works\'']: While executing ValuesBlockInputFormat. (NO_COMMON_TYPE) (version 24.2.3.70 (official build))
But it works without the line including the parens.
importasynciofromaiohttpimportClientSessionfromaiochclientimportChClientasyncdefsome_query(client: ChClient, a: list[tuple[str,str]]):
result=awaitclient.execute(
"INSERT INTO t VALUES", [a]
)
asyncdefmain():
asyncwithClientSession() ass:
client=ChClient(s, url="http://localhost:8123")
# preparing database awaitclient.execute("DROP TABLE IF EXISTS t")
awaitclient.execute("CREATE TABLE IF NOT EXISTS t (a Array(Tuple(String, String))) ENGINE = Memory")
# making queries in parallelawaitasyncio.gather(
some_query(client, [("key1", "value1"), ("key2", "this is an invalid pair(with some parens) and this, let's see if it works")]),
some_query(client, [("key3", "value3"), ("key4", "value4")]),
some_query(client, [("key11", ""), ("key12", "''")]),
)
print("Fetch results:")
results=awaitclient.fetch("SELECT * FROM t")
print([{**r} forrinresults])
forresultinresults:
awaitclient.execute("INSERT INTO t VALUES", [result['a']])
if__name__=="__main__":
# if >=3.7:asyncio.run(main())
The text was updated successfully, but these errors were encountered:
akira
changed the title
Issue inserting and fetching tuple with certain string format
Issue inserting and fetching tuple array with certain string format
Dec 20, 2024
There's an issue when inserting and trying to fetch a tuple array with certain string formatting - in this case parens:
[("key1", "value1"), ("key2", "this is an invalid pair(with some parens) and this, let's see if it works")]
When it is fetched, it comes back as:
Which is not a valid tuple - this cannot be reinserted to Clickhouse.
See code below, this is the entire result fetched:
If trying to reinsert this record as is, we get the error:
But it works without the line including the parens.
The text was updated successfully, but these errors were encountered: