当查询返回空结果时,不会打印标题。有没有办法在任何情况下强制打印标题?
例如,在这种情况下,当结果不是为空时,.headers
pragma确实打印到.output
文件,但是在查询返回空结果的情况下该文件为空(无标题)。我仍然希望在空角的情况下将标题打印到文件,因为生成的输出文件很难用于其他系统,并且它们依赖于这些标题。是否可以在生成的文件中强制标题?
-- setup to provide headers and to output as csv
.headers on
.mode csv
-- Attaching the databases
attach '/tmp/1.db' as existingdb;
attach '/tmp/2.db' as newdb;
-- Deletions query
.output /tmp/test/res/deletes.csv
SELECT a.sku AS "old:sku" , a.c1 AS "old:c1" , a.c2 AS "old:c2" FROM existingdb.products AS a LEFT JOIN newdb.products AS b on a.sku = b.sku WHERE b.sku IS NULL;
另一个微不足道的例子:
sqlite> .tables
sqlite> create table test(a,b,c);
sqlite> select * from test;
sqlite>
sqlite> insert into test values (1,2,3);
sqlite> select * from test;
1|2|3
sqlite> .headers on
sqlite> select * from test;
a|b|c <<< the headers are printed
1|2|3
sqlite> select * from test where a = 2;
sqlite> result is empy - no headers are printed!
答案 0 :(得分:1)
sqlite3
命令行shell在收到第一个结果行之前不会打印标题。
您必须修改shell的源代码,或使用自己的工具。