返回首页

gbase数据、南大通用产品文档:GBase8sSERIAL 和 SERIAL8 数据类型

更新日期:2024年09月11日

通过方法 getSerial() 和 getSerial8(),GBase 8s JDBC Driver 提供对 GBase 8s SERIAL 和
SERIAL8 数据类型的支持,其为 java.sql.Statement接口实现的一部分。
由于 SERIAL 和 SERIAL8 数据类型没有来自 java.sql.Types 类的向任何 JDBC API 数据
类型的明显映射,因此,您必须将特定于 GBase 8s 的类导入至 Java™ 程序内,以处理
SERIAL 和 SERIAL8 列。要这么做,请将下列导入行添加至 Java 程序:
import com.gbasedbt.jdbc.*;
在 INSERT 语句之后,
请使用 getSerial() 方法,
来返回自动插入至表的 SERIAL 列内的序
列值。
在 INSERT 语句之后,
请使用 getSerial8() 方法,
来返回自动插入至表的 SERIAL8 列
内的序列值。如果任何下列条件为真,则这些方法返回 0:

最后的语句不是 INSERT 语句。

正在插入至其内的表不包含 SERIAL 或 SERIAL8 列。

尚未执行 INSERT 语句。
在 CREATE TABLE 语句之后,如果执行 getSerial() 或 getSerial8() 方法,则该方法缺省地
返回 1(假定新表包括一个 SERIAL 或 SERIAL8 列)。如果该表不包含 SERIAL 或
SERIAL8 列,则该方法返回 0。如果指定新的序列起始编号,则该方法返回该编号。
如果您想要使用 getSerial() 和 getSerial8() 方法,
则必须将 Statement 或 PreparedStatement 对
象强制转型为 IfmxStatement,
其为特定于GBase 8s 的 Statement 接口的实现。
下列示例展示
如何执行该强制转型:
cmd = "insert into serialTable(i) values (100)";
stmt.executeUpdate(cmd);
System.out.println(cmd+"...okay");
int serialValue = ((IfmxStatement)stmt).getSerial();
System.out.println("serial value: " + serialValue);

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 109 -

如果您想要将连续的序列值插入至 SERIAL 或 SERIAL8 数据类型的列内,则请为
INSERT 语句中的 SERIAL 或 SERIAL8 列指定值 0。当将该列设置为 0 时,数据库服务
器指定仅次于最高值的值。
要获取关于 GBase 8s SERIAL 和 SERIAL8 数据类型的更详尽信息,
请参阅
《GBase 8s SQL
指南:参考》 和《GBase 8s SQL 指南:语法》 。

语法格式
树结构的数据存放在表中,数据之间的层次关系即父子关系,通过表中的列与列之
间的关系来描述。通过每个节点的父节点,就可以确定整个树的结构。在SELECT
命令中使用START WITH...CONNECT BY 可以查询表中的树形结构关系,其语法
格式如下。
START WITH...CONNECT BY 语法形式:
SELECT column_list|[LEVEL]
FROM single_table
[WHERE …]
[hierarchical_clause]
[GROUP BY …]
[ORDER [SIBLINGS] BY …]
hierarchical_clause :
[START WITH ] CONNECT BY
| CONNECT BY [START WITH ]
[ORDER SIBLINGS BY {col_name | expr | position} [ASC | DESC] , ...]
connect_condition:
PRIOR expr1 op expr2
| expr1 op PRIOR expr2
| expr op connect_condition
| expr
参数说明

START WITH 后面的condition 标识分层查询的所有root rows,START WITH
子句可以省略。

PRIOR 为一元操作符,仅用于CONNECT BY 后面的condition,用于标识紧接
在后面的表达式中涉及的列出自parent row。

CONNECT BY 后面的condition 标识parent row 和child row 之间的连接
condition;
condition 中的表达式中需要通过PRIOR 指定该表达式涉及的列出自
parent row 还是child row,如下例:

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 710
... PRIOR expr_left = expr_right //左表达式中涉及的列出自parent row;
or
... expr_left = PRIOR expr_right //右表达式中涉及的列出自parent row;
PRIOR 只对于紧接在后面的表达式生效,如下例:
expr_1 = expr_2 AND expr_3 = PRIOR expr_4 //PRIOR 只对于expr_4 生效。
PRIOR 不能嵌套使用,如下例会报错:
PRIOR (expr_1 + PRIOR expr2)

CONNECT_BY_ISCYCLE: 伪列,由GBase UP 自动维护。用于表示当前层是
否发生cycle。0 表示未发生cycle;1 表示发生cycle。只有NOCYCLE 存在才
能使用,否则报错

LEVEL:伪列,由GBase UP 自动维护;用于标识分层查询结果所在层级,从
1 开始。

CONNECT_BY_ISLEAF: 伪列,
由GBase UP 自动维护;
用于表示当前层已经
是最后一层。
0 表示非最后一层;
1 表示最后一层。
不能出现在connect_condition
和join_conditions 中。

CONNECT_BY_ROOT: 一元操作符,用于获取结果集中每一条记录对应根记
录的某一列值。参数可以指定多列、表达式或函数。不能出现在
connect_condition 和join_condition 中。

SYS_CONNECT_BY_PATH(column,char): 函数,
可通过使用指定的字符作为连
接符,将分层查询结果的某一列按照分层路径输出。不能出现在
connect_condition 和join_conditions 中。

WHERE: Where 子句中所有连接条件均在hierarchical_clause 之前执行,所有
过滤条件均在hierarchical_clause 之后执行

语法约束:
1) 分级查询子句connect by 与start with 不允许出现外层表的列;
2) 分级查询from 子句必须是表,且必须是复制表;
3) 放到分级查询可以作为子查询出现,但分级查询中不允许出现子查询;
示例1:允许分级查询做子查询:
gbase> select * from (select * from r1 start with id2 = 2 connect by prior
id2 = id2) x;
示例2: 不允许分级查询中出现子查询:
gbase>select
*
from
r1
where
exists
(select
1
from
x2)
start
with
id2
=
2
connect
by prior id2 = id2;
ERROR 1149 (42000): (GBA-02SC-1001) Subquery in hierarchical query is not
allowed

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 711
4) connect by 关联条件不能包含or 操作,并且必须包含父子节点间的等值条
件,等号的两边必须是不同的维度(一边包含prior,一边不包含prior);

5) prior 是一元操作符,优先级同正负号,只能用在connect by 子句中;prior
后面不可以接伪列(level、rowid 等)、不可以接包含伪列的表达式、不可
以嵌套使用prior,不可以接聚合函数;
6) order siblings by 只能用在分级查询语句中,
并且不能同聚合,olap 函数,order
by 同时存在;
7) 不支持实时环路判断,
只能保证最终能够检测出环路,
如果数据量太大
(如
超过十万),会耗时很长才能检测出;
8) 最大节点数为MAX_INT(2147483647)(所有节点数);
9) 新增三个保留字:start level prior;
10)
CONNECT BY 后面的condition 不允许包含subquery;
示例
示例1:level 使用在CONNECT BY 位置。
示例中用到的表及数据:
USE test;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a int, b int, c char(10), d varchar(20), e varchar(5), f datetime, g
decimal(6,2)) REPLICATED;
INSERT INTO t1 VALUES(0,1,'DMD','kds','dmd','2013-4-1 10:23:01',1.1);
INSERT INTO t1 VALUES(0,2,'DMD','cj','dmd','2013-4-1 10:23:01',2.1);
INSERT INTO t1 VALUES (1,3,'DMD','lm','dmd1','2013-4-1 10:23:01',2.2);
INSERT INTO t1 VALUES (1,4,'DMD','zx','dmd2','2013-4-1 10:23:01',2.3);
DROP TABLE IF EXISTS t2;
CREATE TABLE t2 REPLICATED AS SELECT * FROM t1;
level 使用在CONNECT BY 位置:
gbase> SELECT level, t1.* FROM t1 CONNECT BY PRIOR b = level START WITH a = 0;
+-------+------+------+------------+------+------+---------------------+------+
| level | a | b | c | d | e | f | g |
+-------+------+------+------------+------+------+---------------------+------+
| 1 | 0 | 1 | DMD | kds | dmd | 2013-04-01 10:23:01 | 1.10 |
| 1 | 0 | 2 | DMD | cj | dmd | 2013-04-01 10:23:01 | 2.10 |
| 2 | 0 | 1 | DMD | kds | dmd | 2013-04-01 10:23:01 | 1.10 |
| 2 | 0 | 2 | DMD | cj | dmd | 2013-04-01 10:23:01 | 2.10 |
| 2 | 1 | 3 | DMD | lm | dmd1 | 2013-04-01 10:23:01 | 2.20 |
| 3 | 0 | 1 | DMD | kds | dmd | 2013-04-01 10:23:01 | 1.10 |
| 3 | 0 | 2 | DMD | cj | dmd | 2013-04-01 10:23:01 | 2.10 |
| 3 | 1 | 3 | DMD | lm | dmd1 | 2013-04-01 10:23:01 | 2.20 |

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 712
| 3 | 1 | 4 | DMD | zx | dmd2 | 2013-04-01 10:23:01 | 2.30 |
| 4 | 0 | 1 | DMD | kds | dmd | 2013-04-01 10:23:01 | 1.10 |
| 4 | 0 | 2 | DMD | cj | dmd | 2013-04-01 10:23:01 | 2.10 |
| 4 | 1 | 3 | DMD | lm | dmd1 | 2013-04-01 10:23:01 | 2.20 |
| 4 | 1 | 4 | DMD | zx | dmd2 | 2013-04-01 10:23:01 | 2.30 |
| 2 | 1 | 4 | DMD | zx | dmd2 | 2013-04-01 10:23:01 | 2.30 |
+-------+------+------+------------+------+------+---------------------+------+
14 rows in set
示例2:
gbase> select * from dep;
+-------+-----------------+------------+
| depid | depname | upperdepid |
+-------+-----------------+------------+
| 0 | 总经办 | NULL |
| 1 | 开发部 | 0 |
| 2 | 测试部 | 0 |
| 3 | Server 开发部 | 1 |
| 4 | Client 开发部 | 1 |
| 5 | TA 测试部 | 2 |
| 6 | 项目测试部 | 2 |
+-------+-----------------+------------+
select depname , connect_by_root depname "root“ , connect_by_isleaf "isleaf“ ,
level ,
sys_connect_by_path(depname,'/') "path" from dep
start with upperdepid is null connect by prior depid=upperdepid
+-----------------+-----------+--------+-------+------------------
| depname | root | isleaf | level | path |
+-----------------+-----------+--------+-------+------------------
| 总经办 | 总经办 | 0 | 1 | /总经办 |
| 开发部 | 总经办 | 0 | 2 | /总经办/开发部 |
|Server 开发部 | 总经办 | 1 |3 | /总经办/开发部/Server 开发部 |
|Client 开发部 | 总经办 | 1 |3 | /总经办/开发部/Client 开发部 |
| 测试部 | 总经办 | 0 |2 | /总经办/测试部 |
| TA 测试部 | 总经办 | 1 | 3 | /总经办/测试部/TA 测试部 |
| 项目测试部 | 总经办 | 1 | 3 | /总经办/测试部/项目测试部 |
+-----------------+-----------+--------+-------+------------------


GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 713

CheckMaxHandle..............................NG
The item run on 1 nodes.
ng: 1
The ng[gbase8c_5_124] value:
Max open files: 1000000
The value of max open files is 1024 on pid 5436. it must not be less than 1000000.
The value of max open files is 1024 on pid 5508. it must not be less than 1000000.
The value of max open files is 1024 on pid 5579. it must not be less than 1000000.
CheckNTPD...................................NG
gbase8c_5_124: NTPD service is not running, 2022-12-06 14:28:06
CheckOSVer..................................OK
gbase8c_5_124: The current OS is centos 7.8 64bit.
CheckSysParams..............................NG
The item run on 1 nodes.
ng: 1
The ng[gbase8c_5_124] value:
Abnormal reason: variable 'net.ipv4.tcp_retries2' RealValue '12' ExpectedValue
'80'.
Warning reason: variable 'net.ipv4.tcp_retries1' RealValue '3' ExpectedValue
'5'.

GBase 8c 管理员指南
南大通用数据技术股份有限公司
23
Warning reason: variable 'net.ipv4.tcp_syn_retries' RealValue '6' ExpectedValue
'5'.
CheckTHP....................................OK
The item run on 1 nodes.
success: 1
CheckTimeZone...............................OK
The item run on 1 nodes.
success: 1
(consistent)
The success on all nodes value:
+0800
CheckCPU....................................OK
The item run on 1 nodes.
success: 1
CheckSshdService............................OK
The item run on 1 nodes.
success: 1
CheckSshdConfig.........................WARNING
The item run on 1 nodes.
warning: 1
The warning[gbase8c_5_124] value:
Warning reason: UseDNS parameter is not set; expected: no
CheckCrondService...........................OK
The item run on 1 nodes.
success: 1
CheckStack..................................OK
The item run on 1 nodes.
success: 1
(consistent)
The success on all nodes value:
8192
CheckSysPortRange...........................OK
The item run on 1 nodes.
success: 1
CheckMemInfo................................OK
The item run on 1 nodes.
success: 1
(consistent)
The success on all nodes value:
totalMem: 7.63824462890625G
CheckHyperThread............................NG

GBase 8c 管理员指南
南大通用数据技术股份有限公司
24
The item run on 1 nodes.
ng: 1
The ng[gbase8c_5_124] value:
Hyper-threading is down.
CheckTableSpace.............................OK
The item run on 1 nodes.
success: 1
CheckSysadminUser...........................NG
The item run on 1 nodes.
ng: 1
The ng[gbase8c_5_124] value:
There are sysadmin users except gbase:
gha
CheckGUCConsistent..........................OK
All DN instance guc value is consistent.
CheckMaxProcMemory..........................NG
The item run on 1 nodes.
ng: 1
The ng[gbase8c_5_124] value:
parameter max_process_memory setting should not be bigger than
recommended(kb):3203712:
RecommendedMaxMem is 3203712
CN_5001 : 12582912
CheckBootItems..............................OK
The item run on 1 nodes.
success: 1
CheckHashIndex..............................OK
The item run on 1 nodes.
success: 1
CheckPgxcRedistb............................OK
The item run on 1 nodes.
success: 1
CheckNodeGroupName..........................OK
The item run on 1 nodes.
success: 1
CheckTDDate.................................OK
The item run on 1 nodes.
success: 1
CheckDilateSysTab...........................OK

GBase 8c 管理员指南
南大通用数据技术股份有限公司
25
The item run on 1 nodes.
success: 1
CheckKeyProAdj..............................OK
The item run on 1 nodes.
success: 1
CheckProStartTime...........................OK
Basically ,all the gaussdb process start at the same time
CheckFilehandle.............................OK
The item run on 1 nodes.
success: 1
CheckRouting................................OK
The item run on 1 nodes.
success: 1
CheckNICModel...............................OK
The item run on 1 nodes.
success: 1
(consistent)
The success on all nodes value:
version: 1.4.16.0-k-NAPI
model: VMware VMXNET3 Ethernet Controller
CheckDropCache..........................WARNING
The item run on 1 nodes.
warning: 1
The warning[gbase8c_5_124] value:
No DropCache process is running
CheckMpprcFile..............................NG
The item run on 1 nodes.
ng: 1
The ng[gbase8c_5_124] value:
There is no mpprc file
Analysis the check result successfully
Failed. All check items run completed. Total:57
Success:43
Warning:4
NG:9
Error:1
For more information please refer to
/home/gbase/gbase_db/om_f5c5a0af/script/gspylib/inspection/output/CheckRepor
t_inspect_202208185514623739.tar.gz