PostgreSQL 9.5:跳过文本文件中的前两行 [英] PostgreSQL 9.5: Skip first two lines in the text file

查看:54
本文介绍了PostgreSQL 9.5:跳过文本文件中的前两行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the text file to import with the following format:

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

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

I can skip first line by using:

WITH CSV HEADER; 

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

in copy command, but got stuck while skipping second line.

推荐答案

如果您使用 COPY FROM 'filename',您可以改为使用 COPY FROM PROGRAM调用一些 shell 命令,从文件中删除标题并返回其余部分.

If you're using COPY FROM 'filename', you could instead use COPY FROM PROGRAM to invoke some shell command which removes the header from the file and returns the rest.

在 Windows 中:

In 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 执行类似操作,例如:

If you're trying to send a local file to a remote server, you can do something similar through psql, e.g.:

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

这篇关于PostgreSQL 9.5:跳过文本文件中的前两行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆