更新时间:2023-03-17 GMT+08:00

使用指导

下载安装gsql并使用gsql连接集群数据库

关于gsql的下载、安装以及连接集群数据库的具体操作,请参见《数据仓库服务用户指南》中的“使用gsql命令行客户端连接集群”。

示例

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

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

查看表的定义:

1
2
3
4
5
6
\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
INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (1, 'Wood');
INSERT 0 1
INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (2, 'Lake');
INSERT 0 1
INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (3, 'Desert');
INSERT 0 1
INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (4, 'Iron');
INSERT 0 1

切换提示符:

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

查看表:

1
2
3
4
5
6
7
8
dbadmin@[local] postgres=#SELECT * FROM HR.areaS;
 area_id |       area_name        
---------+------------------------
       1 | Wood
       4 | Iron
       2 | Lake
       3 | Desert
(4 rows)

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
dbadmin@[local] postgres=#\pset border 2
Border style is 2.
dbadmin@[local] postgres=#SELECT * FROM HR.areaS;
+---------+------------------------+
| area_id |       area_name        |
+---------+------------------------+
|       1 | Wood                 |
|       2 | Lake               |
|       3 | Desert                   |
|       4 | Iron |
+---------+------------------------+
(4 rows)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dbadmin@[local] postgres=#\pset border 0
Border style is 0.
dbadmin@[local] postgres=#SELECT * FROM HR.areaS;
area_id       area_name        
------- ----------------------
      1 Wood
      2 Lake
      3 Desert
      4 Iron
(4 rows)

使用元命令:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
dbadmin@[local] postgres=#\a \t \x
Output format is unaligned.
Showing only tuples.
Expanded display is on.
dbadmin@[local] postgres=#SELECT * FROM HR.areaS;
area_id|2
area_name|Lake

area_id|1
area_name|Wood

area_id|4
area_name|Iron

area_id|3
area_name|Desert
dbadmin@[local] postgres=#