简体   繁体   English

使用 SQL 将 csv 文件复制到表时出错 Shell (psql)

[英]Error when copying a csv file to a table using SQL Shell (psql)

I have a file test.csv with two lines:我有一个包含两行的文件 test.csv:

"smth", "1", "2", "3"
"smth more", "4", "5", "6"

I'm trying to copy it to a table with sql shell:我正在尝试将其复制到 sql shell 的表中:

CREATE TABLE test_table(col1 TEXT, col2 TEXT, col3 TEXT, col4 TEXT);
COPY test_table FROM 'E:\\PostgreSQL13\\scripts\\test.csv';

And get the following error:并得到以下错误:

 wrong syntax for type integer: """"smth"", ""1"", ""2"", ""3""""

What could be the problem here?这里可能是什么问题?

Thank you!谢谢!

Tell copy you are inputing a csv , so it will use the default comma separator and recognize the double quotes.告诉副本您正在输入csv ,因此它将使用默认的逗号分隔符并识别双引号。 ( text format is the default) (默认为text格式)

COPY test_table FROM 'E:\\PostgreSQL13\\scripts\\test.csv' (FORMAT 'csv')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用psql复制csv时包含NULL值 - Include NULL values when copying csv using psql 从csv文件在PostGreSQL复制中填充表时出现权限错误 - permission error when populating a table in PostGreSQL copying from a csv file 使用 psql 从 csv 文件复制时,null 列的“”会生成错误,而不是 null - When using psql to copy from a csv file, a “” for a null column generates an error instead of a null 使用\\ copy将数据从表导出到CSV文件-psql - Export data from table to CSV file using \copy - psql psql - 读取 SQL 文件并输出到 CSV - psql - read SQL file and output to CSV 将CSV文件复制到PostgreSQL中的表 - Copying a CSV file to a table in PostgreSQL 在PostgreSQL表中复制CSV文件时,将多个值解释为NULL - Interpret several values as NULL when copying CSV file in PostgreSQL table 当做psql副本时,从表到csv文件中选择看高写入 - when doing psql copy as select from table to csv file seeing high writeiops 如果 psql 在执行 sql 脚本时抛出错误,则退出 shell 脚本 - Exit shell script if psql throws error in exectuting sql scripts 将带有空值和空字符串的雪花表复制到可以使用 psql copy 命令导入的 csv - Copying a snowflake table with nulls and empty strings to csv that can be imported with psql copy command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM