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)
    

      

  • 相关阅读:
    Python 学习笔记:需要仔细阅读一个函数
    asp.net 实现一个简单CAS Server
    用代码旋转屏幕
    Cassandra API60 Java 代码示例
    Ajax跨域访问代理类,支持GET和POST方法
    Android 给自己的类加个事件
    Python 学习笔记: 备份工具
    Android SQLiteHelper
    转:在 CLI 中練習 Data Model
    Java修饰符public,private,protected及默认的区别
  • 原文地址:https://www.cnblogs.com/orcl-2018/p/13518358.html
Copyright © 2011-2022 走看看