云数据库 GAUSSDB-使用指导:示例

时间:2024-11-01 17:08:08

示例

以把一个查询分成多行输入为例。注意提示符的变化:

1
2
3
4
5
gaussdb=#  CREATE TABLE HR.areaS(
gaussdb(# area_ID   NUMBER,
gaussdb(# area_NAME VARCHAR2(25)
gaussdb(# )tablespace EXAMPLE;
CREATE TABLE

查看表的定义:

1
2
3
4
5
6
gaussdb=#  \d HR.areaS
               Table "hr.areas"
  Column   |         Type          | Modifiers 
-----------+-----------------------+-----------
 area_id   | numeric               | not null
 area_name | character varying(25) | 

向HR.areaS表插入四行数据:

1
2
3
4
5
6
7
8
gaussdb=#  INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (1, 'Europe');
INSERT 0 1
gaussdb=#  INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (2, 'Americas');
INSERT 0 1
gaussdb=#  INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (3, 'Asia');
INSERT 0 1
gaussdb=#  INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (4, 'Middle East and Africa');
INSERT 0 1

切换提示符:

1
2
gaussdb=#  \set PROMPT1 '%n@%m %~%R%#'
omm@[local] gaussdb=# 

查看表:

1
2
3
4
5
6
7
8
omm@[local] gaussdb=#  SELECT * FROM HR.areaS;
 area_id |       area_name        
---------+------------------------
       1 | Europe
       4 | Middle East and Africa
       2 | Americas
       3 | Asia
(4 rows)

可以用\pset命令以不同的方法显示表:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
omm@[local] gaussdb=#  \pset border 2
Border style is 2.
omm@[local] gaussdb=#  SELECT * FROM HR.areaS;
+---------+------------------------+
| area_id |       area_name        |
+---------+------------------------+
|       1 | Europe                 |
|       2 | Americas               |
|       3 | Asia                   |
|       4 | Middle East and Africa |
+---------+------------------------+
(4 rows)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
omm@[local] gaussdb=#  \pset border 0
Border style is 0.
omm@[local] gaussdb=#  SELECT * FROM HR.areaS;
area_id       area_name        
------- ----------------------
      1 Europe
      2 Americas
      3 Asia
      4 Middle East and Africa
(4 rows)

使用元命令:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
omm@[local] gaussdb=#  \a \t \x
Output format is unaligned.
Showing only tuples.
Expanded display is on.
omm@[local] gaussdb=#  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] gaussdb=# 
support.huaweicloud.com/tg-gaussdb-dist/gaussdb-08-0005.html