返回首页

gbase数据、南大通用产品文档:GBase8a

更新日期:2024年09月11日

Mirror Cluster
The mirror function of the virtual cluster has the following characteristics:
Flexible mirror configuration: supports mirror setting at the database or table
level;
Real-time data synchronization: when data changes occur in databases or tables
with mirror relationships, the changes are synchronized in real-time on both sides.
All tables under mutually mirrored databases will automatically create mirrors. All
functions, stored procedures, and views under the database will also be synchronized
and created in the target database;
High availability: mirror relationships provide more redundant shards for data,
resulting in higher availability; disaster recovery: supports cluster deployment in the
same city or different locations.

GBase 8a MPP Cluster Technical White Paper
General Data Technology Co., Ltd.
- 25 -
Data Security

可以在使用表达式的任何地方使用数据转换函数。
下列转换函数在日期与字符串之间转换:

DATE 函数
DATE 函数将字符串转换为 DATE 值。
在以下查询中,
DATE 函数将字符串转换为 DATE
值,
以允许与 DATETIME 值进行比较。
仅当 call_dtime值比指定的 DATE 晚时查询才会检
索 DATETIME 值。

GBase 8s SQL 指南:教程
南大通用数据技术股份有限公司 - 92 -

图: 查询
SELECT customer_num, call_dtime, res_dtime
FROM cust_calls
WHERE call_dtime > DATE ('12/31/97');
图: 查询结果
customer_num call_dtime res_dtime

106 1998-06-12 08:20 1998-06-12 08:25
110 1998-07-07 10:24 1998-07-07 10:30
119 1998-07-01 15:00 1998-07-02 08:21
121 1998-07-10 14:05 1998-07-10 14:06
127 1998-07-31 14:30
仅当 call_dtime 大于或等于指定日期时,
下列查询才会将 DATETIME 值转换为 DATE 格
式并带标签显示这些值。
图: 查询
SELECT customer_num,
DATE (call_dtime) called,
DATE (res_dtime) resolved
FROM cust_calls
WHERE call_dtime >= DATE ('1/1/98');
图: 查询结果
customer_num called resolved

106 06/12/1998 06/12/1998
110 07/07/1998 07/07/1998
119 07/01/1998 07/02/1998
121 07/10/1998 07/10/1998
127 07/31/1998

TO_CHAR 函数
TO_CHAR 函数将 DATETIME 或 DATE 值转换为字符串值。
TO_CHAR 函数根据您指定
的日期格式化伪指令对 DATETIME 值进行求值并返回 NVARCHAR 值。
有关受支持的日
期格式化伪指令的列表,请参阅《GBase 8s GLS 用户指南》 GL_DATETIME 环境变量的
描述。
还可以使用 TO_CHAR 函数将 DATETIME 或 DATE 值转换为 LVARCHAR 值。

GBase 8s SQL 指南:教程
南大通用数据技术股份有限公司 - 93 -

下列查询使用 TO_CHAR 函数将 DATETIME 值转换为可读性更强的字符串。
图: 查询
SELECT customer_num,
TO_CHAR(call_dtime, "%A %B %d %Y") call_date
FROM cust_calls
WHERE call_code = "B";
图: 查询结果
customer_num 119
call_date Friday July 01 1998
下列查询使用 TO_CHAR 函数将 DATE 值转换为可读性更强的字符串。
图: 查询
SELECT order_num,
TO_CHAR(ship_date,"%A %B %d %Y") date_shipped
FROM orders
WHERE paid_date IS NULL;
图: 查询结果
order_num 1004
date_shipped Monday May 30 1998

order_num 1006
date_shipped

order_num 1007
date_shipped Sunday June 05 1998

order_num 1012
date_shipped Wednesday June 29 1998

order_num 1016
date_shipped Tuesday July 12 1998

order_num 1017
date_shipped Wednesday July 13 1998
TO_CHAR 函数还可以格式化数字值。
有关内置 TO_CHAR 函数的更多信息,
请参阅
《GBase
8s SQL 指南:语法》。

GBase 8s SQL 指南:教程
南大通用数据技术股份有限公司 - 94 -


TO_DATE 函数
TO_DATE 函数接受字符数据类型的参数并将此值转换为 DATETIME 值。
TO_DATE 函数
根据您指定的日期格式化伪指令对字符串求值并返回 DATETIME 值。有关受支持的日期
格式化伪指令的列表,请参阅《GBase 8s GLS 用户指南》中 GL_DATETIME 环境变量的
描述。
还可以使用 TO_DATE 函数将 LVARCHAR 值转换为 DATETIME 值。
下列查询使用 TO_DATE 函数将字符串转换为指定格式的 DATETIME 值。
图: 查询
SELECT customer_num, call_descr
FROM cust_calls
WHERE call_dtime = TO_DATE("2008-07-07 10:24",
"%Y-%m-%d %H:%M");

图: 查询结果
customer_num 110

call_descr Order placed one month ago (6/7) not received.
可以使用 DATE 或 TO_DATE 函数来将字符串转换为 DATE 值。
TO_DATE 函数的一个优
点是它允许您为返回的值指定格式。(可以使用 TO_DATE函数(它总是返回 DATETIME
值)来将字符串转换为 DATE 值,原因是数据库服务器隐式处理 DATE 和 DATETIME
值之间的转换。)


高可用方面
1.以下sql 执行期间不支持failover,若执行节点异常可能会导致存在残留文件,需
要再次执行相关语句或者加force 执行解决
创建/删除单个表镜像:Alter table create/delete mirror
以库为单位创建/删除表镜像:Alter database create/delete mirror
创建库的默认镜像VC:Alter database set default mirror
3.
以下sql 执行时,如果镜像vc 不可用,sql 报错失败退出
创建单个表镜像:Alter table create mirror
以库为单位创建表镜像:Alter database create mirror
同时创建主表和镜像表:CREATE TABLE MIRROR TO
CREATE TABLE MIRROR AS SELECT
4.
Alter database create mirror 若有表创建失败,均会在warnings 中提示,sql 不报
错退出

数据操作方面
1. 镜像表的dml 操作和select 操作:
当前vc 或者镜像vc 有可用分片时,该表均可用
多表关联操作时,需要同一distribution 下的相关表均可用