VastbaseG100

基于openGauss内核开发的企业级关系型数据库。

Menu

反引号解释为标识符

功能描述

Vastbase在MySQL兼容模式下支持使用反引号解释为标识符的功能。遇到反引号的时候,就会将反引号中的内容解释为标识符,同时关键字也会作为标识符返回。

注意事项

该功能仅在数据库兼容模式为MySQL时支持(即数据库实例初始化时指定DBCOMPATIBILITY='B')。

示例

示例1: 在DML语句中使用反引号。

1、创建表。

CREATE TABLE `my_table_1160786`(col_1 int,col_2 text);

2、对表数据进行DML操作。

insert into `my_table_1160786` values (1,'`aa`');
insert into `my_table_1160786`(`col_1`) select 2;
insert into `my_table_1160786`(`col_1`,`col_2`) values (3,'`cc');
insert into `my_table_1160786` set `col_1`=4,col_2='dd';
update `my_table_1160786` set col_2='b' where `col_1`=2;
delete from `my_table_1160786` where col_1=1;

3、查看表数据。

select col_2 from `my_table_1160786` t1 where `t1`.`col_1`=3;
select * from `my_table_1160786` order by `col_1`;

返回结果分别为:

 col_2
-------
 `cc
(1 row)


 col_1 | col_2
-------+-------
     2 | b
     3 | `cc
     4 | dd
(3 rows)

示例2: 在存储过程中使用反引号。

1、创建存储过程。

CREATE PROCEDURE `prc_存储过程_1160834`(id int, `id2` double)
as
BEGIN
if `id`>5 and id2<5 then
raise info '大于5和小于5';
else
raise info '不大于5';
end if;
END;
/

2、调用存储过程。

call `prc_存储过程_1160834`(7,4);

返回结果为:

INFO:  大于5和小于5
 prc_存储过程_1160834
----------------------

(1 row)