Updated on 2023-05-23 GMT+08:00

Viewing Data

  • Query information about all tables in a database through the system catalog pg_tables:
    1
    SELECT * FROM pg_tables;
    
  • Run the \d+ command of the gsql tool to query table attributes:
    1
    \d+ customer_t1;
    
  • Query the data volume of the table customer_t1:
    1
    SELECT count(*) FROM customer_t1;
    
  • Query all data in table customer_t1:
    1
    SELECT * FROM customer_t1;
    
  • Query data in column c_customer_sk:
    1
    SELECT c_customer_sk FROM customer_t1;
    
  • Filter repeated data in column c_customer_sk:
    1
    SELECT DISTINCT( c_customer_sk ) FROM customer_t1;
    
  • Query all data whose column c_customer_sk is 3869:
    1
    SELECT * FROM customer_t1 WHERE c_customer_sk = 3869;
    
  • Sort data based on column c_customer_sk.
    1
    SELECT * FROM customer_t1 ORDER BY c_customer_sk;
    

    To cancel a query that has been running for a long time, see Viewing and Stopping the Running Query Statements in Querying System Catalogs.