PostgreSQL 常用命令

SQL commands

  ABORT                            ALTER TRIGGER                    CREATE RULE                      DROP GROUP                       LISTEN
  ALTER AGGREGATE                  ALTER TYPE                       CREATE SCHEMA                    DROP INDEX                       LOAD
  ALTER COLLATION                  ALTER USER                       CREATE SEQUENCE                  DROP LANGUAGE                    LOCK
  ALTER CONVERSION                 ALTER USER MAPPING               CREATE SERVER                    DROP MATERIALIZED VIEW           MOVE
  ALTER DATABASE                   ALTER VIEW                       CREATE STATISTICS                DROP OPERATOR                    NOTIFY
  ALTER DEFAULT PRIVILEGES         ANALYZE                          CREATE SUBSCRIPTION              DROP OPERATOR CLASS              PREPARE
  ALTER DOMAIN                     BEGIN                            CREATE TABLE                     DROP OPERATOR FAMILY             PREPARE TRANSACTION
  ALTER EVENT TRIGGER              CHECKPOINT                       CREATE TABLE AS                  DROP OWNED                       REASSIGN OWNED
  ALTER EXTENSION                  CLOSE                            CREATE TABLESPACE                DROP POLICY                      REFRESH MATERIALIZED VIEW
  ALTER FOREIGN DATA WRAPPER       CLUSTER                          CREATE TEXT SEARCH CONFIGURATION DROP PUBLICATION                 REINDEX
  ALTER FOREIGN TABLE              COMMENT                          CREATE TEXT SEARCH DICTIONARY    DROP ROLE                        RELEASE SAVEPOINT
  ALTER FUNCTION                   COMMIT                           CREATE TEXT SEARCH PARSER        DROP RULE                        RESET
  ALTER GROUP                      COMMIT PREPARED                  CREATE TEXT SEARCH TEMPLATE      DROP SCHEMA                      REVOKE
  ALTER INDEX                      COPY                             CREATE TRANSFORM                 DROP SEQUENCE                    ROLLBACK
  ALTER LANGUAGE                   CREATE ACCESS METHOD             CREATE TRIGGER                   DROP SERVER                      ROLLBACK PREPARED
  ALTER LARGE OBJECT               CREATE AGGREGATE                 CREATE TYPE                      DROP STATISTICS                  ROLLBACK TO SAVEPOINT
  ALTER MATERIALIZED VIEW          CREATE CAST                      CREATE USER                      DROP SUBSCRIPTION                SAVEPOINT
  ALTER OPERATOR                   CREATE COLLATION                 CREATE USER MAPPING              DROP TABLE                       SECURITY LABEL
  ALTER OPERATOR CLASS             CREATE CONVERSION                CREATE VIEW                      DROP TABLESPACE                  SELECT
  ALTER OPERATOR FAMILY            CREATE DATABASE                  DEALLOCATE                       DROP TEXT SEARCH CONFIGURATION   SELECT INTO
  ALTER POLICY                     CREATE DOMAIN                    DECLARE                          DROP TEXT SEARCH DICTIONARY      SET
  ALTER PUBLICATION                CREATE EVENT TRIGGER             DELETE                           DROP TEXT SEARCH PARSER          SET CONSTRAINTS
  ALTER ROLE                       CREATE EXTENSION                 DISCARD                          DROP TEXT SEARCH TEMPLATE        SET ROLE
  ALTER RULE                       CREATE FOREIGN DATA WRAPPER      DO                               DROP TRANSFORM                   SET SESSION AUTHORIZATION
  ALTER SCHEMA                     CREATE FOREIGN TABLE             DROP ACCESS METHOD               DROP TRIGGER                     SET TRANSACTION
  ALTER SEQUENCE                   CREATE FUNCTION                  DROP AGGREGATE                   DROP TYPE                        SHOW
  ALTER SERVER                     CREATE GROUP                     DROP CAST                        DROP USER                        START TRANSACTION
  ALTER STATISTICS                 CREATE INDEX                     DROP COLLATION                   DROP USER MAPPING                TABLE
  ALTER SUBSCRIPTION               CREATE LANGUAGE                  DROP CONVERSION                  DROP VIEW                        TRUNCATE
  ALTER SYSTEM                     CREATE MATERIALIZED VIEW         DROP DATABASE                    END                              UNLISTEN
  ALTER TABLE                      CREATE OPERATOR                  DROP DOMAIN                      EXECUTE                          UPDATE
  ALTER TABLESPACE                 CREATE OPERATOR CLASS            DROP EVENT TRIGGER               EXPLAIN                          VACUUM
  ALTER TEXT SEARCH CONFIGURATION  CREATE OPERATOR FAMILY           DROP EXTENSION                   FETCH                            VALUES
  ALTER TEXT SEARCH DICTIONARY     CREATE POLICY                    DROP FOREIGN DATA WRAPPER        GRANT                            WITH
  ALTER TEXT SEARCH PARSER         CREATE PUBLICATION               DROP FOREIGN TABLE               IMPORT FOREIGN SCHEMA
  ALTER TEXT SEARCH TEMPLATE       CREATE ROLE                      DROP FUNCTION                    INSERT

psql commands

General
  \copyright             show PostgreSQL usage and distribution terms
  \crosstabview [COLUMNS] execute query and display results in crosstab
  \errverbose            show most recent error message at maximum verbosity
  \g [FILE] or ;         execute query (and send results to file or |pipe)
  \gexec                 execute query, then execute each value in its result
  \gset [PREFIX]         execute query and store results in psql variables
  \gx [FILE]             as \g, but forces expanded output mode
  \q                     quit psql
  \watch [SEC]           execute query every SEC seconds

Help
  \? [commands]          show help on backslash commands
  \? options             show help on psql command-line options
  \? variables           show help on special variables
  \h [NAME]              help on syntax of SQL commands, * for all commands

Query Buffer
  \e [FILE] [LINE]       edit the query buffer (or file) with external editor
  \ef [FUNCNAME [LINE]]  edit function definition with external editor
  \ev [VIEWNAME [LINE]]  edit view definition with external editor
  \p                     show the contents of the query buffer
  \r                     reset (clear) the query buffer
  \s [FILE]              display history or save it to file
  \w FILE                write query buffer to file

Input/Output
  \copy ...              perform SQL COPY with data stream to the client host
  \echo [STRING]         write string to standard output
  \i FILE                execute commands from file
  \ir FILE               as \i, but relative to location of current script
  \o [FILE]              send all query results to file or |pipe
  \qecho [STRING]        write string to query output stream (see \o)

Conditional
  \if EXPR               begin conditional block
  \elif EXPR             alternative within current conditional block
  \else                  final alternative within current conditional block
  \endif                 end conditional block

Informational
  (options: S = show system objects, + = additional detail)
  \d[S+]                 list tables, views, and sequences
  \d[S+]  NAME           describe table, view, sequence, or index
  \da[S]  [PATTERN]      list aggregates
  \dA[+]  [PATTERN]      list access methods
  \db[+]  [PATTERN]      list tablespaces
  \dc[S+] [PATTERN]      list conversions
  \dC[+]  [PATTERN]      list casts
  \dd[S]  [PATTERN]      show object descriptions not displayed elsewhere
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值