zoukankan      html  css  js  c++  java
  • postgresql 运行sql文件

    方法一:
    [postgres@node01 ~]$ psql -Upostgres
    postgres=# l
                                      List of databases
       Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
    -----------+----------+----------+-------------+-------------+-----------------------
     postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
     template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
               |          |          |             |             | postgres=CTc/postgres
     template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
               |          |          |             |             | postgres=CTc/postgres
     test      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
    (4 rows)
    
    postgres=# c test
    You are now connected to database "test" as user "postgres".
    test=# i /stage/company.sql
    DROP TABLE
    CREATE TABLE
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    test=# select * from company;
     id | name  | age |                      address                       | salary
    ----+-------+-----+----------------------------------------------------+--------
      1 | Paul  |  32 | California                                         |  20000
      2 | Allen |  25 | Texas                                              |  15000
      3 | Teddy |  23 | Norway                                             |  20000
      4 | Mark  |  25 | Rich-Mond                                          |  65000
      5 | David |  27 | Texas                                              |  85000
      6 | Kim   |  22 | South-Hall                                         |  45000
      7 | James |  24 | Houston                                            |  10000
    (7 rows)
    
    方法二:
    [postgres@node01 ~]$ psql -Upostgres -d test0 -f /stage/company.sql
    DROP TABLE
    CREATE TABLE
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    [postgres@node01 ~]$ psql -Upostgres
    psql.bin (10.14)
    Type "help" for help.
    
    postgres=# l
                                      List of databases
       Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
    -----------+----------+----------+-------------+-------------+-----------------------
     postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
     template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
               |          |          |             |             | postgres=CTc/postgres
     template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
               |          |          |             |             | postgres=CTc/postgres
     test      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
     test0     | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
    (5 rows)
    
    postgres=# c test0
    You are now connected to database "test0" as user "postgres".
    test0=# d
              List of relations
     Schema |  Name   | Type  |  Owner
    --------+---------+-------+----------
     public | company | table | postgres
    (1 row)
    
    test0=# select * from company;
     id | name  | age |                      address                       | salary
    ----+-------+-----+----------------------------------------------------+--------
      1 | Paul  |  32 | California                                         |  20000
      2 | Allen |  25 | Texas                                              |  15000
      3 | Teddy |  23 | Norway                                             |  20000
      4 | Mark  |  25 | Rich-Mond                                          |  65000
      5 | David |  27 | Texas                                              |  85000
      6 | Kim   |  22 | South-Hall                                         |  45000
      7 | James |  24 | Houston                                            |  10000
    (7 rows)
    

      

  • 相关阅读:
    数据规范化(normalization)
    《穷爸爸富爸爸》笔记
    期望,方差,协方差,相关系数,协方差矩阵,相关系数矩阵,以及numpy实现
    numpy array和mat的乘法
    matlab多图排列
    POJ 3463
    POJ 3463
    Poj2449 第k短路
    Poj2449 第k短路
    POJ 3013
  • 原文地址:https://www.cnblogs.com/orcl-2018/p/13518358.html
Copyright © 2011-2022 走看看