如何导入 CSV?

发布于 2024-09-10 02:52:57 字数 587 浏览 7 评论 0原文

我有一个如下所示的 CSV 文件:

id, name
0, A.D. TRAMONTANA
1, Abarth
2, Abbot-Detroit
3, AC
...

我正在尝试通过 phpPgAdmin 将其导入到我的表中。

它给了我这个错误:

SQL error:

ERROR:  column "id, name" of relation "app_vehiclemake" does not exist
LINE 1: INSERT INTO "public"."app_vehiclemake" ("id, name") VALUES (...
                                                ^

In statement:
INSERT INTO "public"."app_vehiclemake" ("id, name") VALUES ('0, A.D. TRAMONTANA')

它看起来像是引用 "id, name" 作为一个列名称。不太确定为什么...我的 CSV 应该采用什么格式?找不到任何这方面的文档!

I've got a CSV file that looks like this:

id, name
0, A.D. TRAMONTANA
1, Abarth
2, Abbot-Detroit
3, AC
...

I'm trying to import it into my table via phpPgAdmin.

It gives me this error:

SQL error:

ERROR:  column "id, name" of relation "app_vehiclemake" does not exist
LINE 1: INSERT INTO "public"."app_vehiclemake" ("id, name") VALUES (...
                                                ^

In statement:
INSERT INTO "public"."app_vehiclemake" ("id, name") VALUES ('0, A.D. TRAMONTANA')

It looks like it's quoting "id, name" as one column name. Not really sure why... what format should my CSV be in? Can't find any documentation on this!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪都笑了 2024-09-17 02:52:57

PHP fgetcsv() 函数,通常用于从 CSV 文件中读取一行,需要:

  • , 作为字段之间的分隔符
  • " 作为封装,对于每个字段的每个数据。

所以也许只需将 double -每条数据都加引号可以吗?

Something like this, I'd say :

"id","name"
"0","A.D. TRAMONTANA"
"1","Abarth"
"2","Abbot-Detroit"
"3","AC"

(嗯,不确定......但可能值得一试?)

The PHP fgetcsv() function, which is often used to read a line from a CSV file, expects :

  • , as a delimiter between fields
  • " as enclosure, for each data of each field.

So maybe just putting double-quotes arround each piece of data would work ?

Something like this, I'd say :

"id","name"
"0","A.D. TRAMONTANA"
"1","Abarth"
"2","Abbot-Detroit"
"3","AC"

(Well, not sure... But might be worth a try ?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文