Re: Importing data from CSV into a table with array and composite types - Mailing list pgsql-general

From Pavel Stehule
Subject Re: Importing data from CSV into a table with array and composite types
Date
Msg-id CAFj8pRBzi_t0vdkqPrFJ3y2Ar2w5Wdf7UP2YZKD6ArzaAx-84g@mail.gmail.com
Whole thread Raw
In response to Importing data from CSV into a table with array and composite types  ("a" <372660931@qq.com>)
Responses Re: Importing data from CSV into a table with array and composite types  ("a" <372660931@qq.com>)
List pgsql-general
Hi

2018-05-18 10:37 GMT+02:00 a <372660931@qq.com>:
Hi:

I would like to import data from a csv table. But the table that is going to be inserted is constructed with arrays and composite types, also with array of composite.

I have tried many ways of inserting but fail. Can anyone help? Thank you so much.

create type p as (a int, b int);
create table f(pv p[], c int);
insert into f values(array[(10,20),(30,40)]::p[], 1000);
insert into f values(array[(1,20),(3,40)]::p[], -1000);

postgres=# copy f to stdout csv;
"{""(10,20)"",""(30,40)""}",1000
"{""(1,20)"",""(3,40)""}",-1000
Time: 0,391 ms

So you have to respect this format. CSV doesn't know a arrays, doesn't know composite - so these values are passed as string

Regards

Pavel

pgsql-general by date:

Previous
From: "a"
Date:
Subject: Importing data from CSV into a table with array and composite types
Next
From: "Peter J. Holzer"
Date:
Subject: Re: Out of memory error with PG10.3, 10.4 but not 9.3.19