返回首页

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

更新日期:2024年09月11日

搜索表
在不使用索引的情况下也可以进行全文检索。

一个简单查询:将body 字段中包含america 的每一行打印出来。
gbase=#DROP SCHEMA IF EXISTS tsearch CASCADE;
gbase=#CREATE SCHEMA tsearch;
gbase=#CREATE TABLE tsearch.pgweb(id int, body text, title text, last_mod_date
date);
gbase=#INSERT INTO tsearch.pgweb VALUES(1, 'China, officially the People''s
Republic of China (PRC), located in Asia, is the world''s most populous state.',
'China', '2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(2, 'America is a rock band, formed in
England in 1970 by multi-instrumentalists Dewey Bunnell, Dan Peek, and Gerry
Beckley.', 'America', '2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(3, 'England is a country that is part of
the United Kingdom. It shares land borders with Scotland to the north and Wales
to the west.', 'England',
'2010-1-1');

GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
630
gbase=#INSERT INTO tsearch.pgweb VALUES(4, 'Australia, officially the
Commonwealth of Australia, is a country comprising the mainland of the Australian
continent, the island of Tasmania, and numerous smaller islands.', 'Australia',
'2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(5, 'Russia, also officially known as the
Russian Federation, is a sovereign state in northern Eurasia.', 'Russia',
'2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(6, 'Japan is an island country in East
Asia.', 'Japan', '2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(7, 'Germany, officially the Federal
Republic of Germany, is a sovereign state and federal parliamentary republic in
central-western Europe.', 'Germany', '2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(8, 'France, is a sovereign state
comprising territory in western Europe and several overseas regions and
territories.', 'France', '2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(9, 'Italy officially the Italian Republic,
is a unitary parliamentary republic in Europe.', 'Italy', '2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(10, 'India, officially the Republic of
India, is a country in South Asia.', 'India', '2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(11, 'Brazil, officially the Federative
Republic of Brazil, is the largest country in both South America and Latin
America.', 'Brazil', '2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(12, 'Canada is a country in the northern
half of North America.', 'Canada', '2010-1-1');
gbase=#INSERT INTO tsearch.pgweb VALUES(13, 'Mexico, officially the United
Mexican States, is a federal republic in the southern part of North America.',
'Mexico', '2010-1-1');
gbase=#SELECT id, body, title FROM tsearch.pgweb WHERE to_tsvector('english',
body) @@ to_tsquery('english', 'america');
id |
body
| title

GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
631
----
+----------------------------------------------------------------------------
-----------------------------------------
----+---------
2 | America is a rock band, formed in England in 1970 by multi-instrumentalists
Dewey Bunnell, Dan Peek, and Gerry Beckley. | America
12| Canada is a country in the northern half of North America. | Canada
13| Mexico, officially the United Mexican States, is a federal republic in the
southern part of North America.
| Mexico
11 | Brazil, officially the Federative Republic of Brazil, is the largest country
in both South America and Latin America. | Brazil
(4 rows)
像America 这样的相关词也会被找到,因为这些词都被处理成了相同标准的词条。
上面的查询指定english 配置来解析和规范化字符串。当然也可以省略此配置,通过
default_text_search_config 进行配置设置:
gbase=#SHOW default_text_search_config; default_text_search_config
----------------------------
pg_catalog.english (1 row)
gbase=#SELECT id, body, title FROM tsearch.pgweb WHERE to_tsvector(body) @@
to_tsquery('america');
id |
body
| title
|
+----------------------------------------------------------------------------
-----------------------------------------
----+---------
11 | Brazil, officially the Federative Republic of Brazil, is the largest country
in both South America and Latin America. | Brazil
2 | America is a rock band, formed in England in 1970 by multi-instrumentalists
Dewey Bunnell, Dan Peek, and Gerry Beckley. | America
12| Canada is a country in the northern half of North America. | Canada
13| Mexico, officially the United Mexican States, is a federal republic in the
southern part of North America.
| Mexico
(4 rows)

一个复杂查询:
检索出在title 或者body 字段中包含north 和america 的最近10 篇文档:
gbase=#SELECT title FROM tsearch.pgweb WHERE to_tsvector(title || ' ' || body)
@@ to_tsquery('north & america') ORDER BY last_mod_date DESC LIMIT 10;
title
--------

GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
632
Mexico Canada (2 rows)
为了清晰,举例中没有调用coalesce 函数在两个字段中查找包含NULL 的行。
以上例子均在没有索引的情况下进行查询。对于大多数应用程序来说,这个方法很慢。
因此除了偶尔的特定搜索,文本搜索在实际使用中通常需要创建索引。

dtcvasc() 函数将符合 ANSI SQL 标准的 DATETIME 值的字符串转换为
datetime 值。
要获取关于 ANSI SQL DATETIME 标准的信息,请参阅 DATETIME 和
INTERVAL 值的 ANSI SQL 标准。
语法
mint dtcvasc(inbuf, dtvalue)
char *inbuf;
dtime_t *dtvalue;
inbuf
指向包含 ANSI 标准 DATETIME 字符串的缓冲区的指针。
dtvalue
指向初始化的 datetime 变量的指针。

用法
您必须以您想要此变量拥有的限定符,来初始化 dtvalue 中的 datetime 变量。

inbuf 中的字符串必须有符合 year to second 限定符的值,该限定符的格式为 ANSI
SQL。
inbuf 字符串可有开头的和结尾的空格。
然而,
从第一个有效位至最后一个,
inbuf 仅
可包含符合 ANSI SQL 标准的 DATETIME 值的数字和定界符的字符。


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 676 -

如果您指定年份值作为一个或两个数字,
则 dtcvasc() 函数假定该年份在当前世纪中。
您可设置该 DBCENTURY 环境变量来确定,当您省略来自该日期的世纪时,dtcvasc() 使
用哪个世纪。

如果该字符串为空字符串,则 dtcvasc() 函数将 dtvalue 指向的值设置为空。如果该
字符串是可接受的,则函数设置 datetime 变量中的值,并返回零。否则,函数保持该变量
不变,并返回负的错误代码。

返回代码
0
转换成功。
-1260
不可能在指定的类型之间转换。
-1261
在 datetime 或 interval 的第一个字段中数字太多。
-1262
在 datetime 或 interval 中的非数值字符。
-1263
在 datetime 或 interval 值中的字段超出范围或不正确。
-1264
在 datetime 或 interval 的末尾存在额外的字符。
-1265
在 datetime 或 interval 运算上发生溢出。
-1266
datetime 或 interval 值与该运算不兼容。
-1267
datetime 计算的结果超出范围。
-1268
参数包含无效的 datetime 限定符。
示例
demo 目录在 dtcvasc.ec 文件中包含此样例程序。
/*

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 677 -

* dtcvasc.ec *
The following program converts ASCII datetime strings in ANSI SQL format into datetime
(dtime_t) structure.
*/

#include

EXEC SQL include datetime;

main()
{
mint x;

EXEC SQL BEGIN DECLARE SECTION;
datetime year to second dt1;
EXEC SQL END DECLARE SECTION;

printf("DTCVASC Sample ESQL Program running.\n\n");

printf("Datetime string #1 = 2007-02-11 3:10:35\n");
if (x = dtcvasc("2007-02-11 3:10:35", &dt1))
printf("Result = failed with conversion error: %d\n", x);
else
printf("Result = successful conversion\n");

/*
* Note that the following literal string has a 26 in the hours place
*/
printf("\nDatetime string #2 = 2007-02-04 26:10:35\n");
if (x = dtcvasc("2007-02-04 26:10:35", &dt1))
printf("Result = failed with conversion error: %d\n", x);
else
printf("Result = successful conversion\n");

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 678 -


printf("\nDTCVASC Sample Program over.\n\n");
}
输出
DTCVASC Sample ESQL Program running.

Datetime string #1 = 2007-02-11 3:10:35
Result = successful conversion

Datetime string #2 = 2007-02-04 26:10:35
Result = failed with conversion error:-1263
DTCVASC Sample Program over.

功能说明
记录存储过程及函数信息。
表结构说明
表5- 288 表结构信息说明:




Vc_id
虚拟集群名
db
数据库名
name
过程及函数名
type
存储过程或函数类型
specific_name
过程及函数名
language
说明子程序是由SQL 语句组成的,当前系统支持的语言为
SQL,SQL 是其唯一值
sql_data_access
存储过程数据存取特征
Contains_sql:子程序不包含读或写数据的语句
no_sql:子程序不包含SQL 语句
reads_sql:子程序包含读数据的语句,但不包含写数据的语句
data modifies_sql_data:子程序包含写数据的语句
is_deterministic
输出结果的确定性
Yes:相同的输入会得到相同的输出
No:相同的输入可能得到不通的输出
security_type
指定谁有权限来执行
Invoker:拥有权限的调用者可以执行
Definer:只有定义者可以执行
param_list
参数列表
returns
返回值类型
body
过程或函数定义
definer
创建者
created
创建时间
modified
修改时间
sql_mode
sql 的执行模式
comment
注释
character_set_client
client 字符集
collation_connection
连接的字符集对照方法
db_collation
数据库的字符集对照方法

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-09-15)
南大通用数据技术股份有限公司
1500
body_utf8
utf8 格式下的定义