0

尝试使用联合运算符或子选择在具有 RoS(只读备用)的 HADR 数据库中执行一些查询,我收到错误 SQL1773N 原因代码 5。

是什么原因?它们是不生成写入的操作。

联盟

with hist(start_time, operationtype) as (
 select start_time, operationtype
 from sysibmadm.db_history
 where operation = 'B' )
select 'delta', timestampdiff(8, current timestamp - char(timestamp(max(start_time))))
from hist
where operationtype = 'D' or operationtype = 'E'
union all
select 'delta', timestampdiff(8, current timestamp - char(timestamp(max(start_time))))
from hist
where operationtype = 'I' or operationtype = 'O'

子选择

with hist(start_time, operationtype) as (
 select start_time, operationtype
 from sysibmadm.db_history
 where operation = 'B' )
select 'delta', operationtype, start_time, timestampdiff(8, current timestamp - char(timestamp(start_time)))
from hist
where start_time = (
 select max(start_time)
 from hist
 where operationtype = 'D' or operationtype = 'E')
4

1 回答 1

2

这似乎是特定于sysibmadm.db_history.
在启用了 ROS的情况下尝试了以下union allsubSelect待机,并且都运行良好

CREATE TABLE TAB101  (
id bigint NOT NULL,
createTimestamp TIMESTAMP NOT NULL,
primary key (id))

insert into tab101 (id, CREATETIMESTAMP) values 
(1, current timestamp - 35 minutes), 
(2, current timestamp - 30 minutes),
(3, current timestamp - 25 minutes), 
(4, current timestamp - 20 minutes),
(5, current timestamp - 15 minutes), 
(6, current timestamp - 10 minutes),
(7, current timestamp - 5 minutes), 
(8, current timestamp)

with tempTab101 (id, CREATETIMESTAMP) as (
  select id, CREATETIMESTAMP from tab101
)
select id, CREATETIMESTAMP from tempTab101 
where id > 1
union all
select id, CREATETIMESTAMP from tempTab101
where id <= 10

with tempTab101 (id, CREATETIMESTAMP) as (
  select id, CREATETIMESTAMP from tab101
)
select * from tempTab101
where id = (
  select id from tempTab101 where id=2
)
于 2017-10-17T21:19:53.907 回答