在 clickhouse-client 中执行 SELECT * FROM test_table;
时,我按预期得到 N 行,但在执行 engine.execute('SELECT * FROM test_table;') 时只有 N-2
来自使用 sqlalchemy 的 python 代码。
重现步骤:
- clickhouse-server 在本地主机上运行。
- 在clickhouse-client中执行以下命令:
CREATE TABLE test_table (id INTEGER, created Date) ENGINE = MergeTree(created, (id), 8192);
INSERT INTO test_table (id, created) VALUES (1, 11345678);
INSERT INTO test_table (id, created) VALUES (2, 12345678);
INSERT INTO test_table (id, created) VALUES (3, 13345678);
INSERT INTO test_table (id, created) VALUES (4, 14345678);
SELECT * FROM test_table;
结果:
SELECT *
FROM test_table
┌─id─┬────created─┐
│ 4 │ 2106-02-07 │
└────┴────────────┘
┌─id─┬────created─┐
│ 3 │ 2084-08-20 │
└────┴────────────┘
┌─id─┬────created─┐
│ 2 │ 2038-03-15 │
└────┴────────────┘
┌─id─┬────created─┐
│ 1 │ 1991-10-08 │
└────┴────────────┘
4 rows in set. Elapsed: 0.004 sec.
好的,符合预期的 4 行。
- 执行以下 python 脚本:
from sqlalchemy import create_engine
connection_string = 'clickhouse://default:@localhost/default'
engine = create_engine(connection_string)
result = list(engine.execute('SELECT * FROM test_table;'))
print(len(result))
print(result)
结果:
2
[('4', '2106-02-07'), ('2', '2038-03-15')]
绝对不是想象中的那样。那么,这是怎么回事?
sqlalchemy 版本:1.3.11
clickhouse版本(服务端和客户端):19.17.4.11
最佳答案
修改connection_string = 'clickhouse+native://default:@localhost/default'
引用:https://github.com/xzkostyan/clickhouse-sqlalchemy/issues/10
关于python - clickhouse + sqlalchemy : SELECT drops two rows from result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59105030/