暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

腾讯云原生数据库 TDSQL-C -SQL 基本操作

原创 腾讯云数据库 2021-08-13
881

TDSQL-C(兼容 MySQL 版)SQL 基本操作
查询版本
方法一:

MySQL [(none)]> SELECT CYNOS_VERSION();
±-----------------------+
| CYNOS_VERSION() |
±-----------------------+
| 5.7.mysql_cynos.1.3.10 |
±-----------------------+
1 row in set (0.00 sec)
方法二:

MySQL [(none)]> SELECT @@CYNOS_VERSION;
±-----------------------+
| @@CYNOS_VERSION |
±-----------------------+
| 5.7.mysql_cynos.1.3.10 |
±-----------------------+
1 row in set (0.00 sec)
方法三:

MySQL [(none)]> SHOW VARIABLES LIKE ‘CYNOS_VERSION’;
±--------------±-----------------------+
| Variable_name | Value |
±--------------±-----------------------+
| cynos_version | 5.7.mysql_cynos.1.3.10 |
±--------------±-----------------------+
1 row in set (0.01 sec)
TDSQL-C(兼容 PostgreSQL 版)SQL 基本操作
查询版本
postgres=# select cynosdb_version(); cynosdb_version
————————
CynosDB 1.0
(1 row)
建表使用
postgres=# create table x(x1 int, x2 int);
CREATE TABLE
postgres=# insert into x values(1, 2);
INSERT 0 1
postgres=# update x set x1 = 1;
UPDATE 1
创建视图
postgres=# create view v_x as select * from x;
CREATE VIEW
postgres=# select * from v_x;
x1 | x2
——+——
1 | 2
(1 row)
查询使用
postgres=# select * from x;

x1 | x2
——+——
1 | 2
(1 row)
系统表
TDSQL-C 完全支持 PG10 系统表,例如 pg_class, pg_proc 等。

GUC 参数
TDSQL-C 兼容 PG10 的 GUC 参数,使用 SHOW 或者 SET 命令可以显示和设置 GUC 参数。

index
TDSQL-C 支持多种索引:B-tree、Hash、GiST、SP-GiST、GIN 以及 BRIN,默认的 CREATE INDEX 创建的是 B-tree 索引。

多列和单列索引
postgres=# CREATE TABLE test2 (
postgres(# major int,
postgres(# minor int,
postgres(# name varchar
postgres(# );
CREATE TABLE
支持多列索引
postgres=# CREATE INDEX test2_mm_idx ON test2 (major, minor);
CREATE INDEX
支持单列索引
postgres=# CREATE INDEX test2_mm ON test2 (name);
CREATE INDEX
表达式索引
与 PG10 兼容,TDSQL-C 支持表达式索引。

postgres=# CREATE INDEX test2_expr ON test2 ((major + minor));
CREATE INDEX

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论