[英]pgAdmin4: Importing a CSV
I am trying to import a CSV using pgAdmin4. I created the table using the query,
CREATE TABLE i210_2017_02_18
(
PROBE_ID character varying(255),
SAMPLE_DATE timestamp without time zone,
LAT numeric,
LON numeric,
HEADING integer,
SPEED integer,
PROBE_DATA_PROVIDER character varying(255),
SYSTEM_DATE timestamp without time zone
)
The header and first line of my CSV read is...
PROBE_ID,SAMPLE_DATE,LAT,LON,HEADING,SPEED,PROBE_DATA_PROVIDER,SYSTEM_DATE
841625st,2017-02-18 00:58:19,34.11968,-117.80855,91.0,9.0,FLEET53,2017-02-18 00:58:58
When I try to use the import dialogue, the process fails with Error Code 1:
ERROR: invalid input syntax for type timestamp: "SAMPLE_DATE"
CONTEXT: COPY i210_2017_02_18, line 1, column sample_date: "SAMPLE_DATE"
Nothing seems wrong to me - any ideas?
According to your table structure, this import will fail in the columns HEADING
and SPEED
, since their values have decimals and you declared them as INTEGER
.根据您的表结构,此导入将在
HEADING
和SPEED
列中失败,因为它们的值有小数并且您将它们声明为INTEGER
。 Either remove the decimals or change the column type to eg NUMERIC
.删除小数或将列类型更改为例如
NUMERIC
。
Having said that, just try this from pgAdmin (considering that file and database are in the same server):话虽如此,只需从 pgAdmin 尝试一下(考虑到文件和数据库位于同一服务器中):
COPY i210_2017_02_18 FROM '/home/jones/file.csv' CSV HEADER;
In case you're dealing with a remote server, try this using psql
from your console:如果您正在处理远程服务器,请在控制台中使用
psql
尝试此操作:
$ cat file.csv | psql yourdb -c "COPY i210_2017_02_18 FROM STDIN CSV HEADER;"
You can also check this answer .你也可以检查这个答案。
In case you really want to stick to the pgAdmin import tool, which I discourage, just select the Header
option and the proper Delimiter
:如果您真的想坚持使用我不鼓励的 pgAdmin 导入工具,只需 select
Header
选项和正确的Delimiter
:
Have you set the Header-Option = TRUE?您是否设置了 Header-Option = TRUE? Import settings
导入设置
that should work.那应该工作。
Step 1: Create a table.第 1 步:创建表。 you can use a query or dashboard to create a table.
您可以使用查询或仪表板来创建表。
Step 2: Create the exact number of columns present in the CSV file.第 2 步:创建 CSV 文件中存在的确切列数。 I would recommend creating columns using the dashboard.
我建议使用仪表板创建列。
Step 3: Click on your table_name in pgadmin you will see an option for import/export.第 3 步:在 pgadmin 中单击您的 table_name,您将看到一个导入/导出选项。
Step 4: provide the path of your CSV file, remember to choose delimiter as comma,第四步:提供你的 CSV 文件的路径,记得选择分隔符为逗号,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.