PostgreSQL12 copy命令支持where子句筛选

copy命令允许我们对数据库中的数据和文件系统中的文件进行交互。pg12对copy命令有了增强,支持了where子句用来筛选。

语法:

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

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

where option can be one of:

    FORMAT format_name
    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'

例子:

bill=# create table t_copy (id int , info text, crt_Time timestamp);  
CREATE TABLE  
bill=# insert into t_copy select generate_series(1,100000), md5(random()::Text), clock_timestamp();  
INSERT 0 100000  
bill=# copy t_copy to '/tmp/t_copy';  
COPY 100000  
bill=# create table t_from (like t_copy);  
CREATE TABLE  
bill=# copy t_from from '/home/pg12/t_copy' where id<100;  
COPY 99  

参考链接:
https://www.postgresql.org/docs/devel/sql-copy.html
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=31f3817402da736b29014ace470cf70aeb126ac5

发布了70 篇原创文章 · 获赞 5 · 访问量 3122

猜你喜欢

转载自blog.csdn.net/weixin_39540651/article/details/103926661