• 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)
    

      

  • 相关阅读:
    UVa Live 3942 Remember the Word
    UVa 11019 Matrix Matcher
    bzoj 4445 小凸想跑步
    Codeforces 832E Vasya and Shifts
    二值法方法综述及matlab程序
    排序算法(1)-插入,选择,冒泡
    如果我想了解一个陌生人
    Libsvm在matlab环境下使用指南
    科学预测世界杯-采用机器学习方法
    应用笔画宽度变换(SWT)来检测自然场景中的文本
  • 原文地址:https://www.cnblogs.com/orcl-2018/p/13518358.html
Copyright © 2020-2023  润新知