zoukankan      html  css  js  c++  java
  • PostgreSQL数据导出导入COPY

    [postgres@DELL-R720 bin]$ ./psql -p 6432
    psql (9.4.5)
    Type "help" for help.

    postgres=# 
    postgres=# h copy
    Command: COPY
    Description: copy data between a file and a table
    Syntax:
    COPY table_name [ ( column_name [, ...] ) ]
    FROM { 'filename' | PROGRAM 'command' | STDIN }
    [ [ WITH ] ( option [, ...] ) ]

    COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
    TO { 'filename' | PROGRAM 'command' | STDOUT }
    [ [ WITH ] ( option [, ...] ) ]

    where option can be one of:

    FORMAT format_name
    OIDS [ boolean ]
    FREEZE [ boolean ]
    DELIMITER 'delimiter_character'
    NULL 'null_string'
    HEADER [ boolean ]
    QUOTE 'quote_character'
    ESCAPE 'escape_character'
    FORCE_QUOTE { ( column_name [, ...] ) | * }
    FORCE_NOT_NULL ( column_name [, ...] )
    FORCE_NULL ( column_name [, ...] )
    ENCODING 'encoding_name'

    postgres=# d+
    List of relations
    Schema | Name | Type | Owner | Size | Description 
    --------+------------+-------+--------------+----------+-------------
    public | customer | table | benchmarksql | 1772 MB | 
    public | district | table | benchmarksql | 152 kB | 
    public | history | table | benchmarksql | 250 MB | 
    public | item | table | benchmarksql | 10184 kB | 
    public | new_order | table | benchmarksql | 38 MB | 
    public | oorder | table | benchmarksql | 198 MB | 
    public | order_line | table | benchmarksql | 3000 MB | 
    public | stock | table | benchmarksql | 3392 MB | 
    public | warehouse | table | benchmarksql | 40 kB | 
    (9 rows)

    postgres=# copy stock to '/tmp/stock.sql';
    COPY 10000000
    postgres=# truncate stock ;
    TRUNCATE TABLE
    postgres=# d+
    List of relations
    Schema | Name | Type | Owner | Size | Description 
    --------+------------+-------+--------------+----------+-------------
    public | customer | table | benchmarksql | 1772 MB | 
    public | district | table | benchmarksql | 152 kB | 
    public | history | table | benchmarksql | 250 MB | 
    public | item | table | benchmarksql | 10184 kB | 
    public | new_order | table | benchmarksql | 38 MB | 
    public | oorder | table | benchmarksql | 198 MB | 
    public | order_line | table | benchmarksql | 3000 MB | 
    public | stock | table | benchmarksql | 0 bytes | 
    public | warehouse | table | benchmarksql | 40 kB | 
    (9 rows)

    postgres=# copy stock from /tmp/stock.sql ;
    ERROR: syntax error at or near "/" at character 18
    STATEMENT: copy stock from /tmp/stock.sql ;
    ERROR: syntax error at or near "/"
    LINE 1: copy stock from /tmp/stock.sql ;
    ^
    postgres=# copy stock from '/tmp/stock.sql' ;
    COPY 10000000
    postgres=# d+
    List of relations
    Schema | Name | Type | Owner | Size | Description 
    --------+------------+-------+--------------+----------+-------------
    public | customer | table | benchmarksql | 1772 MB | 
    public | district | table | benchmarksql | 152 kB | 
    public | history | table | benchmarksql | 250 MB | 
    public | item | table | benchmarksql | 10184 kB | 
    public | new_order | table | benchmarksql | 38 MB | 
    public | oorder | table | benchmarksql | 198 MB | 
    public | order_line | table | benchmarksql | 3000 MB | 
    public | stock | table | benchmarksql | 3392 MB | 
    public | warehouse | table | benchmarksql | 40 kB | 
    (9 rows)

  • 相关阅读:
    Mysql索引优化
    [ExtJS5学习笔记]第六节 Extjs的类系统Class System命名规则及定义和调试
    [ExtJS5学习笔记]第五节 使用fontawesome给你的extjs5应用增加字体图标
    【翻译】Ext JS 5.0.1 中的新功能
    OpenCV——PS图层混合算法(六)
    [IDE工具配置]myeclipse 2014 专业版 安装 svn插件
    OpenCV——PS 图层混合算法 (四)
    [ExtJS5学习笔记]第四节 欢迎来到extjs5-手把手教你实现你的第一个应用
    [ExtJS5学习笔记]第三节 sencha cmd学习笔记 生成应用程序构建的内部细节
    [ExtJS5学习笔记]第二节 Sencha Cmd 学习笔记 使你的sencha cmd跑起来
  • 原文地址:https://www.cnblogs.com/xmzzp/p/6284292.html
Copyright © 2011-2022 走看看