单击house+sqlalchemy:SELECT从resu中删除两行

2024-06-16 12:49:27 发布

您现在位置:Python中文网/ 问答频道 /正文

在clickhouse客户机中执行SELECT * FROM test_table;时,我得到了N行,但在使用sqlalchemy的python代码中执行engine.execute('SELECT * FROM test_table;')时只有N-2行。你知道吗

复制步骤:

  1. clickhouse服务器正在本地主机上运行。你知道吗
  2. 在clickhouse客户端中执行以下命令:
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排。你知道吗

  1. 执行以下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


Tags: fromtest服务器idexecutesqlalchemytableresult