#openGauss #入门 #安装 #数据库 #开源
知识来源:docs-opengauss.osinfra.cn/zh/
示例
首先要创建一个表空间EXAMPLE:
openGauss=# CREATE TABLESPACE EXAMPLE RELATIVE LOCATION 'tablespace1/tablespace_1';
CREATE TABLESPACE
表空间创建成功后,创建schema HR:
openGauss=# CREATE schema HR;
CREATE SCHEMA
以把一个查询分成多行输入为例。注意提示符的变化:
openGauss=# CREATE TABLE HR.areaS(
openGauss(# area_ID NUMBER,
openGauss(# area_NAME VARCHAR2(25)
openGauss(# )tablespace EXAMPLE;
CREATE TABLE
查看表的定义:
openGauss=# \d HR.areaS
Table "hr.areas"
Column | Type | Modifiers
-----------+-----------------------+-----------
area_id | numeric |
area_name | character varying(25) |
Tablespace: "example"
向HR.areaS表插入四行数据:
openGauss=# INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (1, 'Europe');
INSERT 0 1
openGauss=# INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (2, 'Americas');
INSERT 0 1
openGauss=# INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (3, 'Asia');
INSERT 0 1
openGauss=# INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (4, 'Middle East and Africa');
INSERT 0 1
切换提示符:
openGauss=# \set PROMPT1 '%n@%m %~%R%#'
omm@[local] openGauss=#
查看表:
omm@[local] openGauss=#SELECT * FROM HR.areaS;
area_id | area_name
---------+------------------------
1 | Europe
4 | Middle East and Africa
2 | Americas
3 | Asia
(4 rows)
可以用\pset命令以不同的方法显示表:
omm@[local] openGauss=#\pset border 2
Border style is 2.
omm@[local] openGauss=#SELECT * FROM HR.areaS;
+---------+------------------------+
| area_id | area_name |
+---------+------------------------+
| 1 | Europe |
| 2 | Americas |
| 3 | Asia |
| 4 | Middle East and Africa |
+---------+------------------------+
(4 rows)
omm@[local] openGauss=#\pset border 0
Border style is 0.
omm@[local] openGauss=#SELECT * FROM HR.areaS;
area_id area_name
------- ----------------------
1 Europe
2 Americas
3 Asia
4 Middle East and Africa
(4 rows)
omm@[local] openGauss=#\pset border 2
Border style is 2.
omm@[local] openGauss=#SELECT * FROM HR.areaS;
+---------+------------------------+
| area_id | area_name |
+---------+------------------------+
| 1 | Europe |
| 2 | Americas |
| 3 | Asia |
| 4 | Middle East and Africa |
+---------+------------------------+
(4 rows)
omm@[local] openGauss=#\pset border 0
Border style is 0.
omm@[local] openGauss=#SELECT * FROM HR.areaS;
area_id area_name
------- ----------------------
1 Europe
2 Americas
3 Asia
4 Middle East and Africa
(4 rows)
omm@[local] openGauss=#\pset border 2
Border style is 2.
omm@[local] openGauss=#SELECT * FROM HR.areaS;
+---------+------------------------+
| area_id | area_name |
+---------+------------------------+
| 1 | Europe |
| 2 | Americas |
| 3 | Asia |
| 4 | Middle East and Africa |
+---------+------------------------+
(4 rows)
omm@[local] openGauss=#\pset border 0
Border style is 0.
omm@[local] openGauss=#SELECT * FROM HR.areaS;
area_id area_name
------- ----------------------
1 Europe
2 Americas
3 Asia
4 Middle East and Africa
(4 rows)
使用元命令:
omm@[local] openGauss=#\a \t \x
Output format is unaligned.
Showing only tuples.
Expanded display is on.
omm@[local] openGauss=#SELECT * FROM HR.areaS;
area_id|2
area_name|Americas
area_id|1
area_name|Europe
area_id|4
area_name|Middle East and Africa
area_id|3
area_name|Asia
omm@[local] openGauss=#
#openGauss #入门 #安装 #数据库 #开源