返回首页

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

更新日期:2024年09月11日

tsquery 类型表示检索条件,存储用于检索的词汇,并且使用布尔操作符&(AND)
,|
(OR)
和!
(NOT)
来组合他们,
括号用来强调操作符的分组。
to_tsquery 函数及plainto_tsquery
函数会将单词转换为tsquery 类型前进行规范化处理。
gbase=# SELECT 'fat & rat'::tsquery;
tsquery
---------------
'fat' & 'rat'
(1 row)
gbase=# SELECT 'fat & (rat | cat)'::tsquery;
tsquery
---------------------------
'fat' & ( 'rat' | 'cat' )
(1 row)
gbase=# SELECT 'fat & rat & ! cat'::tsquery;
tsquery
------------------------
'fat' & 'rat' & !'cat'
(1 row)
在没有括号的情况下,!(非)结合的最紧密,而&(和)结合的比|(或)紧密。
tsquery 中的词汇可以用一个或多个权字母来标记,这些权字母限制这些词汇只能与带
有匹配权的tsvector 词汇进行匹配。
gbase=# SELECT 'fat:ab & cat'::tsquery;
tsquery
------------------
'fat':AB & 'cat'
(1 row)
同样,tsquery 中的词汇可以用*标记来指定前缀匹配。例如,匹配tsvector 中以super
开始的任意单词:
gbase=# SELECT 'super:*'::tsquery;
tsquery
-----------
'super':*
(1 row)

GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
73
需要注意的是,文本搜索分词器会首先处理前缀。例如:
gbase=# SELECT to_tsvector( 'postgraduate' ) @@ to_tsquery( 'postgres:*' ) AS
RESULT;
result
--------
t
(1 row)
例如,将postgres 处理后得到postgr,则可以匹配postgraduate:
gbase=# SELECT to_tsquery('postgres:*');
to_tsquery
------------
'postgr':*
(1 row)
例如,将'Fat:ab & Cats'规范化转为tsquery 类型:
gbase=# SELECT to_tsquery('Fat:ab & Cats');
to_tsquery
------------------
'fat':AB & 'cat'
(1 row)

ifx_var_getlen() 函数返回 lvarchar pointer 或 var binary 主变量中数据的长度。

语法
var binary
mint ifx_var_getlen(var_bin)
var binary **var_bin;

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

lvarchar
mint ifx_var_getlen(lvar)
lvarchar **lvar;

var_bin
返回其长度的 var binary 主变量的地址。
lvar
返回其长度的 lvarchar pointer 主变量的地址。

用法
ifx_var_getlen() 函数返回的长度是已为 lvar 或 var_bin 主变量的数据缓冲区分配了
的字节数。

如果您通过使用 GET DESCRIPTOR 语句的 DATA 子句从描述符区域取得
lvarchar pointer 或 var binary,则该值以空终止。如果对这样一个变量使用
ifx_var_getlen(),则返回的长度包括空终止符。要取得正确的长度,请使用 GET
DESCRIPTOR 语句的 LENGTH 子句。

返回代码

>=0
var_bin 主变量的数据缓冲区的长度。
<0
函数不成功。

100 |20
gsql -d human_resource -p 15432
gsql ((GBase8c 3.0.0BXX build d28887c9) compiled at 2022-05-13 11:31:40 commit 0 last mr
55 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
human_resource=# drop table hr.staffs CASCADE; NOTICE: drop cascades to view
hr.staff_details_view DROP TABLE
gs_restore /home/gbase/backup/MPPDB_backup.tar -p 15432 -d human_resource -n hr -t staffs
-s -e Password:
restore operation successful
total time: 904 ms

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
322
示例九:执行gs_restore,导入staffs 和areas 两个指定表的定义和数据。在导入之前,
staffs 和areas 表不存在。
human_resource=# \d
List of relations Schema
Name
| Type | Owner |
Storage
--------+--------------------+-------+----------+----------------------------------
hr
| employment_history | table | gbase | {orientation=row,compression=no}
hr | employments | table | gbase | {orientation=row,compression=no}
hr | places | table | gbase | {orientation=row,compression=no}
hr | sections | table | gbase | {orientation=row,compression=no}
hr | states | table | gbase | {orientation=row,compression=no}
(5 rows)
gs_restore /home/gbase/backup/MPPDB_backup.tar -p 15432 -d human_resource -n hr -t staffs
-n hr -t areas
Password:
restore operation successful total time: 724 ms
human_resource=# \d
List of relations
Schema |
Name
| Type
| Owner
| Storage
--------+--------------------+-------+----------+----------------------------------
hr
| areas | table | gbase | {orientation=row,compression=no}
hr
| employment_history | table | gbase | {orientation=row,compression=no}
hr
| employments
| table | gbase | {orientation=row,compression=no}
hr | places | table | gbase | {orientation=row,compression=no}
hr | sections | table | gbase | {orientation=row,compression=no}
hr | staffs | table | gbase | {orientation=row,compression=no}
hr | states | table | gbase | {orientation=row,compression=no}
(7 rows)
human_resource=# select * from hr.areas; area_id |
area_name
---------+------------------------
4 | Middle East and Africa 1 | Europe
| Americas
| Asia
(4 rows)
示例十:执行gs_restore,导入hr 的模式,包含模式下的所有对象定义和数据。
gs_restore /home/gbase/backup/MPPDB_backup1.dmp -p 15432 -d backupdb -n hr -e
Password:
restore operation successful total time: 702 ms

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
323
示例十一:执行gs_restore,同时导入hr 和hr1 两个模式,仅导入模式下的所有对象定
义。
gs_restore /home/gbase/backup/MPPDB_backup2.dmp -p 15432 -d backupdb -n hr -n hr1 -s
Password:
restore operation successful total time: 665 ms
示例十二:
执行gs_restore,
将human_resource 数据库导出文件导入至backupdb 数据库
中。
postgres=# create database backupdb;
CREATE DATABASE
gs_restore /home/gbase/backup/MPPDB_backup.tar -p 15432 -d backupdb
restore operation successful total time: 23472 ms
gsql -d backupdb -p 15432 -r
gsql ((GBase8c 3.0.0BXX build d28887c9) compiled at 2022-05-13 11:31:40 commit 0 last mr
55 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
gbase=#
postgres=# select * from hr.areas;
area_id |area_name
---------+------------------------
4 | Middle East and Africa 1 | Europe
| Americas
| Asia
(4 rows)
示例十三:
用户user1 不具备将导出文件中数据导入至数据库backupdb 的权限,
而角色
role1 具备该权限,要实现将文件数据导入数据库backupdb,可以在导出命令中设置--role
角色为role1,使用role1 的权限,完成导出目的。
human_resource=# CREATE USER user1 IDENTIFIED BY "1234@abc"; CREATE ROLE
role1 with SYSADMIN IDENTIFIED BY "abc@1234";
gs_restore -U user1 /home/gbase/backup/MPPDB_backup.tar -p 15432 -d backupdb --role role1
-- rolepassword abc@1234
Password:
restore operation successful total time: 554 ms
gsql -d backupdb -p 15432 -r
gsql ((GBase8c 3.0.0BXX build d28887c9) compiled at 2022-05-13 11:31:40 commit 0 last mr
55 )

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
324
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=# select * from hr.areas;
area_id |
area_name
---------+------------------------
4 | Middle East and Africa
1 | Europe
| Americas
| Asia
(4 rows)