语法

默认情况下,数据库安装成功,登录后,可以使用\help语句查看所有openGauss的SQL语法。

  1. openGauss=# \help
  2. Available help:
  3. ABORT ALTER TABLE CREATE DATABASE CREATE TEXT SEARCH CONFIGURATION DROP OPERATOR MERGE
  4. ALTER APP WORKLOAD GROUP ALTER TABLE PARTITION CREATE DIRECTORY CREATE TEXT SEARCH DICTIONARY DROP OWNED MOVE
  5. ALTER APP WORKLOAD GROUP MAPPING ALTER TABLESPACE CREATE EXTENSION CREATE TRIGGER DROP PACKAGE PREPARE
  6. ALTER AUDIT POLICY ALTER TEXT SEARCH CONFIGURATION CREATE FOREIGN TABLE CREATE TYPE DROP PACKAGE BODY PREPARE TRANSACTION
  7. ALTER DATA SOURCE ALTER TEXT SEARCH DICTIONARY CREATE FUNCTION CREATE USER DROP PROCEDURE PUBLISH SNAPSHOT
  8. ALTER DATABASE ALTER TRIGGER CREATE GROUP CREATE VIEW DROP RESOURCE LABEL PURGE SNAPSHOT
  9. ALTER DEFAULT PRIVILEGES ALTER TYPE CREATE INDEX CREATE WEAK PASSWORD DICTIONARY DROP RESOURCE POOL REASSIGN OWNED
  10. ALTER DIRECTORY ALTER USER CREATE LANGUAGE CREATE WORKLOAD GROUP DROP ROLE REFRESH MATERIALIZED VIEW
  11. ALTER EXTENSION ALTER VIEW CREATE MASKING POLICY CURSOR DROP ROW LEVEL SECURITY POLICY REINDEX
  12. ALTER FOREIGN TABLE ALTER WORKLOAD GROUP CREATE MATERIALIZED VIEW DEALLOCATE DROP SCHEMA RESET
  13. ALTER FOREIGN TABLE FOR HDFS ANALYSE CREATE MODEL DECLARE DROP SEQUENCE REVOKE
  14. ALTER FUNCTION ANALYZE CREATE NODE DELETE DROP SERVER ROLLBACK
  15. ALTER GROUP ANONYMOUS BLOCK CREATE NODE GROUP DO DROP SYNONYM ROLLBACK PREPARED
  16. ALTER INDEX ARCHIVE SNAPSHOT CREATE OPERATOR DROP APP WORKLOAD GROUP DROP TABLE SAMPLE SNAPSHOT
  17. ALTER LARGE OBJECT BEGIN CREATE PACKAGE DROP APP WORKLOAD GROUP MAPPING DROP TABLESPACE SAVEPOINT
  18. ALTER MASKING POLICY CALL CREATE PACKAGE BODY DROP AUDIT POLICY DROP TEXT SEARCH CONFIGURATION SELECT
  19. ALTER MATERIALIZED VIEW CHECKPOINT CREATE PROCEDURE DROP CLIENT MASTER KEY DROP TEXT SEARCH DICTIONARY SELECT INTO
  20. ALTER NODE CLEAN CONNECTION CREATE RESOURCE LABEL DROP COLUMN ENCRYPTION KEY DROP TRIGGER SET
  21. ALTER NODE GROUP CLOSE CREATE RESOURCE POOL DROP DATA SOURCE DROP TYPE SET CONSTRAINTS
  22. ALTER OPERATOR CLUSTER CREATE ROLE DROP DATABASE DROP USER SET ROLE
  23. ALTER RESOURCE LABEL COMMENT CREATE ROW LEVEL SECURITY POLICY DROP DIRECTORY DROP VIEW SET SESSION AUTHORIZATION
  24. ALTER RESOURCE POOL COMMIT CREATE SCHEMA DROP EXTENSION DROP WEAK PASSWORD DICTIONARY SET TRANSACTION
  25. ALTER ROLE COMMIT PREPARED CREATE SEQUENCE DROP FOREIGN TABLE DROP WORKLOAD GROUP SHOW
  26. ALTER ROW LEVEL SECURITY POLICY COPY CREATE SERVER DROP FUNCTION END START TRANSACTION
  27. ALTER SCHEMA CREATE APP WORKLOAD GROUP CREATE SNAPSHOT AS DROP GROUP EXECUTE TRUNCATE
  28. ALTER SEQUENCE CREATE APP WORKLOAD GROUP MAPPING CREATE SNAPSHOT FROM DROP INDEX EXECUTE DIRECT UPDATE
  29. ALTER SERVER CREATE AUDIT POLICY CREATE SYNONYM DROP MASKING POLICY EXPLAIN VACUUM
  30. ALTER SESSION CREATE BARRIER CREATE TABLE DROP MATERIALIZED VIEW FETCH VALUES
  31. ALTER SYNONYM CREATE CLIENT MASTER KEY CREATE TABLE AS DROP MODEL GRANT
  32. ALTER SYSTEM KILL SESSION CREATE COLUMN ENCRYPTION KEY CREATE TABLE PARTITION DROP NODE INSERT
  33. ALTER SYSTEM SET CREATE DATA SOURCE CREATE TABLESPACE DROP NODE GROUP LOCK

\h name命令可以查看具体的语法信息。例如:

  1. openGauss=# \h ABORT
  2. Command: ABORT
  3. Description: abort the current transaction
  4. Syntax:
  5. ABORT [ WORK | TRANSACTION ] ;

SQL语句

一个SQL语句通常包含了关键字、标识符(字段)、常量、特殊符号。例如,简单的SQL语句:

  1. SELECT id, name FROM t1;

-

SELECT

id, name

FROM

t1

符号类型

关键字

标识符(字段)

关键字

标识符

描述

命令

id和name字段

语句,用于设置条件规则等

表名

关于SQL语法请见附录:SQL语法