pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: a <372660931@qq.com>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Importing data from CSV into a table with array and composite types
Date: Sun, 20 May 2018 13:36:09 +0800
Message-ID: <tencent_1EB03C8A12AA94DA2F14F01A@qq.com> (raw)
In-Reply-To: <CAFj8pRBzi_t0vdkqPrFJ3y2Ar2w5Wdf7UP2YZKD6ArzaAx-84g@mail.gmail.com>
References: <tencent_541F5F531C51513630805758@qq.com>
	<CAFj8pRBzi_t0vdkqPrFJ3y2Ar2w5Wdf7UP2YZKD6ArzaAx-84g@mail.gmail.com>

Thank you so much. BTW, may I ask one more question that, how should I select every first element of the array??


I know that "select p[:] from f" will print all element of the p array, but I probably would want to present result as "select p[:].a from f", but the statement does not work.


May I as the correct statement of displaying all first element of the composite type in an array??


Thank you!


Shore 




------------------ Original message ------------------
From: "Pavel Stehule"; 
Sendtime: Friday, May 18, 2018 5:46 PM
To: "a"<372660931@qq.com>; 
Cc: "pgsql-general"; 
Subject: Re: Importing data from CSV into a table with array and composite types



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

view thread (4+ messages)  latest in thread

Message-ID: <tencent_1EB03C8A12AA94DA2F14F01A@qq.com>
Permalink:  ../tencent_1EB03C8A12AA94DA2F14F01A@qq.com/
Also on:    postgresql.org/message-id/tencent_1EB03C8A12AA94DA2F14F01A@qq.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: 372660931@qq.com, pavel.stehule@gmail.com
  Subject: Re: Importing data from CSV into a table with array and composite types
  In-Reply-To: <tencent_1EB03C8A12AA94DA2F14F01A@qq.com>
  References: <tencent_541F5F531C51513630805758@qq.com> <CAFj8pRBzi_t0vdkqPrFJ3y2Ar2w5Wdf7UP2YZKD6ArzaAx-84g@mail.gmail.com> <tencent_1EB03C8A12AA94DA2F14F01A@qq.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox