gpt4 book ai didi

PostgreSQL 9.5 : Skip first two lines in the text file

转载 作者:行者123 更新时间:2023-11-29 11:58:58 26 4
gpt4 key购买 nike

我有以下格式的文本文件要导入:

columA    | columnB    |    columnC
-----------------------------------------
1 | A | XYZ
2 | B | XZ
3 | C | YZ

我可以使用以下方法跳过第一行:

WITH CSV HEADER; 

在复制命令中,但在跳过第二行时卡住了。

最佳答案

如果您正在使用 COPY FROM 'filename',您可以改为使用 COPY FROM PROGRAM 来调用一些 shell 命令,该命令从文件中删除 header 并返回休息。

在 Windows 中:

COPY t FROM PROGRAM 'more +2 "C:\Path\To\File.txt"'

在 Linux 中:

COPY t FROM PROGRAM 'tail -n +3 /path/to/file.txt'

如果你试图将本地文件发送到远程服务器,你可以通过 psql 做类似的事情,例如:

tail -n +3 file.txt | psql -c 'COPY t FROM STDIN'

关于PostgreSQL 9.5 : Skip first two lines in the text file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42242179/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com