SQL

如何在Netezza NZSQL中使用制表符分隔符输出文件

发布于 2021-06-04 17:04:23

我正在尝试使用NZSQL CLI输出某些文件,但无法以制表符分隔的文件形式输出。可以为在NZ工作的人分享您对以下命令的看法。

到目前为止尝试过:

nzsql  -o sample.txt -F=  -A -t -c  "SELECT * FROM DW_ETL.USER WHERE datasliceid % 20 = 2 LIMIT 5;"
关注者
0
被浏览
107
1 个回答
  • 面试哥
    面试哥 2021-06-04
    为面试而生,有面试问题,就找面试哥。

    若要将制表符指定为定界符,请结合使用$和-F选项。

    nzsql  -o sample.txt -F $'\t'  -A -t -c  "SELECT * FROM DW_ETL.USER WHERE datasliceid % 20 = 2 LIMIT 5;"
    

    记录在nzsql -h输出中。

    nzsql -h
    This is nzsql, the IBM Netezza SQL interactive terminal.
    
    Usage:
      nzsql [options] [security options] [dbname [username] [password]]
    
    Security Options:
      -securityLevel       Security Level you wish to request (default: preferredUnSecured)
      -caCertFile          ROOT CA certificate file (default: NULL)
    
    Options:
      -a                   Echo all input from script
      -A                   Unaligned table output mode (-P format=unaligned)
      -c <query>           Run only single query (or slash command) and exit
      -d <dbname>          Specify database name to connect to (default: system)
      -D <dbname>          Specify database name to connect to (default: system)
      -schema <schemaname> Specify schema name to connect to (default: $NZ_SCHEMA)
      -e                   Echo queries sent to backend
      -E                   Display queries that internal commands generate
      -f <filename>        Execute queries from file, then exit
      -F <string>          Set field separator (default: "|") (-P fieldsep=)
                           For any binary/control/non-printable character use '$'
                           (e.g., nzsql -F $'\t' // for TAB)
    ...
    

    如果您有大量数据,建议您改用外部表,因为它们的性能更好。

    CREATE EXTERNAL TABLE '/tmp/sample.txt' USING (DELIMITER '\t') 
    AS SELECT * FROM DW_ETL.USER WHERE datasliceid % 20 = 2 LIMIT 5;
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看