测试数据库:
create table a ( d date not null primary key);
create table b ( d date not null primary key);
insert into a values ('2013-01-01');
insert into b values ('2014-01-01');
使用带有 Delphi 7 的 Zeos lib,这些查询都返回 TDateTimeField:
select d from a order by 1;
select d from b order by 1;
select d from a union all select d from b;
select * from (select d from a union all select d from b) s;
然而,这个查询返回一个 TStringField:
select * from (select d from a union all select d from b) s order by 1;
问题:
- 这是为什么?
- 我该如何防止这种情况发生?
- 这是一个错误吗?究竟如何对结果集进行排序会更改列的类型????
- 这是一个严重的问题,因为我无法从我的程序生成 SQL 查询并在设计时创建的 TZReadOnlyQuery 中打开它们
更新:它也不适用于整数。
create table c ( id integer not null primary key);
create table d ( id integer not null primary key);
insert into c values(1);
insert into d values(2);
这些导致 TLageIntField:
select * from c order by 1
select * from d order by 1
select * from ( select * from c union all select * from d) s
然而,这会产生一个 TStringField:
select * from ( select * from c union all select * from d) s order by 1