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

时间:2023-11-01 16:22:10

示例

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

12345
openGauss=# CREATE TABLE HR.areaS(openGauss(# area_ID   NUMBER,openGauss(# area_NAME VARCHAR2(25)openGauss-# )tablespace EXAMPLE;CREATE TABLE

查看表的定义:

123456
openGauss=# \d HR.areaS               Table "hr.areas"  Column   |         Type          | Modifiers -----------+-----------------------+----------- area_id   | numeric               | not null area_name | character varying(25) | 

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

12345678
openGauss=# INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (1, 'Europe');INSERT 0 1openGauss=# INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (2, 'Americas');INSERT 0 1openGauss=# INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (3, 'Asia');INSERT 0 1openGauss=# INSERT INTO HR.areaS (area_ID, area_NAME) VALUES (4, 'Middle East and Africa');INSERT 0 1

切换提示符:

12
openGauss=# \set PROMPT1 '%n@%m %~%R%#'omm@[local] openGauss=#

查看表:

12345678
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命令以不同的方法显示表:

 1 2 3 4 5 6 7 8 9101112
omm@[local] openGauss=# \pset border 2Border 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)
 1 2 3 4 5 6 7 8 910
omm@[local] openGauss=# \pset border 0Border 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)

使用元命令:

 1 2 3 4 5 6 7 8 91011121314151617
omm@[local] openGauss=# \a \t \xOutput format is unaligned.Showing only tuples.Expanded display is on.omm@[local] openGauss=# SELECT * FROM HR.areaS;area_id|2area_name|Americasarea_id|1area_name|Europearea_id|4area_name|Middle East and Africaarea_id|3area_name|Asiaomm@[local] openGauss=#
support.huaweicloud.com/centralized-devg-v2-opengauss/devg_03_0028.html