pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedHow do I copy an element of composite type array into csv file?
6+ messages / 3 participants
[nested] [flat]
* How do I copy an element of composite type array into csv file?
@ 2018-05-23 08:35 a <372660931@qq.com>
2018-05-23 08:41 ` Re: How do I copy an element of composite type array into csv file? amul sul <sulamul@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: a @ 2018-05-23 08:35 UTC (permalink / raw)
To: pgsql-general
Hi suppose I have composite type and table
create type A as(
x float8,
y float8
);
create table B(
Ay A[]
);
insert into B
values(array[
(1,2)::A,
(3,4)::B]
);
Now I would like to export the first element of table B into an csv file:
COPY B(Ay[1])
to 'E:/products_199.csv' DELIMITER ',' CSV HEADER;
The code above reported an syntax error.
How should I do it??
Thank you so much!
Shore
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How do I copy an element of composite type array into csv file?
2018-05-23 08:35 How do I copy an element of composite type array into csv file? a <372660931@qq.com>
@ 2018-05-23 08:41 ` amul sul <sulamul@gmail.com>
2018-05-23 08:47 ` Re: How do I copy an element of composite type array into csv file? a <372660931@qq.com>
0 siblings, 1 reply; 6+ messages in thread
From: amul sul @ 2018-05-23 08:41 UTC (permalink / raw)
To: a <372660931@qq.com>; +Cc: pgsql-general
On Wed, May 23, 2018 at 2:05 PM, a <372660931@qq.com> wrote:
> Hi suppose I have composite type and table
>
> create type A as(
> x float8,
> y float8
> );
>
> create table B(
> Ay A[]
> );
>
> insert into B
> values(array[
> (1,2)::A,
> (3,4)::B]
> );
>
> Now I would like to export the first element of table B into an csv file:
>
> COPY B(Ay[1])
> to 'E:/products_199.csv' DELIMITER ',' CSV HEADER;
>
> The code above reported an syntax error.
>
> How should I do it??
>
Try COPY (SELECT Ay[1] FROM B) to 'E:/products_199.csv' DELIMITER ','
CSV HEADER;
Regards,
Amul
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How do I copy an element of composite type array into csv file?
2018-05-23 08:35 How do I copy an element of composite type array into csv file? a <372660931@qq.com>
2018-05-23 08:41 ` Re: How do I copy an element of composite type array into csv file? amul sul <sulamul@gmail.com>
@ 2018-05-23 08:47 ` a <372660931@qq.com>
2018-05-23 13:18 ` How do I copy an element of composite type array into csv file? David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: a @ 2018-05-23 08:47 UTC (permalink / raw)
To: amul sul <sulamul@gmail.com>; +Cc: pgsql-general
Thank you very much.
BTW, may I ask if I would like to do the opposite that copy csv file content into the first element, how should I do it??
COPY B(Ay[1])
from 'E:/products_199.csv' DELIMITER ',' CSV HEADER;
------------------ Original ------------------
From: "amul sul";<sulamul@gmail.com>;
Send time: Wednesday, May 23, 2018 5:11 PM
To: "a"<372660931@qq.com>;
Cc: "pgsql-general"<pgsql-general@postgresql.org>;
Subject: Re: How do I copy an element of composite type array into csv file?
On Wed, May 23, 2018 at 2:05 PM, a <372660931@qq.com> wrote:
> Hi suppose I have composite type and table
>
> create type A as(
> x float8,
> y float8
> );
>
> create table B(
> Ay A[]
> );
>
> insert into B
> values(array[
> (1,2)::A,
> (3,4)::B]
> );
>
> Now I would like to export the first element of table B into an csv file:
>
> COPY B(Ay[1])
> to 'E:/products_199.csv' DELIMITER ',' CSV HEADER;
>
> The code above reported an syntax error.
>
> How should I do it??
>
Try COPY (SELECT Ay[1] FROM B) to 'E:/products_199.csv' DELIMITER ','
CSV HEADER;
Regards,
Amul
^ permalink raw reply [nested|flat] 6+ messages in thread
* How do I copy an element of composite type array into csv file?
2018-05-23 08:35 How do I copy an element of composite type array into csv file? a <372660931@qq.com>
2018-05-23 08:41 ` Re: How do I copy an element of composite type array into csv file? amul sul <sulamul@gmail.com>
2018-05-23 08:47 ` Re: How do I copy an element of composite type array into csv file? a <372660931@qq.com>
@ 2018-05-23 13:18 ` David G. Johnston <david.g.johnston@gmail.com>
2018-05-23 14:03 ` Re:How do I copy an element of composite type array into csv file? a <372660931@qq.com>
0 siblings, 1 reply; 6+ messages in thread
From: David G. Johnston @ 2018-05-23 13:18 UTC (permalink / raw)
To: a <372660931@qq.com>; +Cc: amul sul <sulamul@gmail.com>; pgsql-general
On Wednesday, May 23, 2018, a <372660931@qq.com> wrote:
> Thank you very much.
>
> BTW, may I ask if I would like to do the opposite that copy csv file
> content into the first element, how should I do it??
>
> COPY B(Ay[1])
> from 'E:/products_199.csv' DELIMITER ',' CSV HEADER;
>
you cannot put "[1]" there. The csv file value has to be an array input
literal with only one element. i.e., something like: {(1,2)}
There is no first element as such when you are creating a new record.
There will be however many elelements to supply to the array input.
David J.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re:How do I copy an element of composite type array into csv file?
2018-05-23 08:35 How do I copy an element of composite type array into csv file? a <372660931@qq.com>
2018-05-23 08:41 ` Re: How do I copy an element of composite type array into csv file? amul sul <sulamul@gmail.com>
2018-05-23 08:47 ` Re: How do I copy an element of composite type array into csv file? a <372660931@qq.com>
2018-05-23 13:18 ` How do I copy an element of composite type array into csv file? David G. Johnston <david.g.johnston@gmail.com>
@ 2018-05-23 14:03 ` a <372660931@qq.com>
2018-05-23 14:13 ` Re: How do I copy an element of composite type array into csv file? David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: a @ 2018-05-23 14:03 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: amul sul <sulamul@gmail.com>; pgsql-general
Thank you so much, did you mean the section 8.15.6??
------------------ Original message ------------------
From: "David G. Johnston";
Sendtime: Wednesday, May 23, 2018 9:18 PM
To: "a"<372660931@qq.com>;
Cc: "amul sul"; "pgsql-general";
Subject: How do I copy an element of composite type array into csv file?
On Wednesday, May 23, 2018, a <372660931@qq.com> wrote:
Thank you very much.
BTW, may I ask if I would like to do the opposite that copy csv file content into the first element, how should I do it??
COPY B(Ay[1])
from 'E:/products_199.csv' DELIMITER ',' CSV HEADER;
you cannot put "[1]" there. The csv file value has to be an array input literal with only one element. i.e., something like: {(1,2)}
There is no first element as such when you are creating a new record. There will be however many elelements to supply to the array input.
David J.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How do I copy an element of composite type array into csv file?
2018-05-23 08:35 How do I copy an element of composite type array into csv file? a <372660931@qq.com>
2018-05-23 08:41 ` Re: How do I copy an element of composite type array into csv file? amul sul <sulamul@gmail.com>
2018-05-23 08:47 ` Re: How do I copy an element of composite type array into csv file? a <372660931@qq.com>
2018-05-23 13:18 ` How do I copy an element of composite type array into csv file? David G. Johnston <david.g.johnston@gmail.com>
2018-05-23 14:03 ` Re:How do I copy an element of composite type array into csv file? a <372660931@qq.com>
@ 2018-05-23 14:13 ` David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: David G. Johnston @ 2018-05-23 14:13 UTC (permalink / raw)
To: a <372660931@qq.com>; +Cc: amul sul <sulamul@gmail.com>; pgsql-general
On Wed, May 23, 2018 at 7:03 AM, a <372660931@qq.com> wrote:
> Thank you so much, did you mean the section 8.15.6??
Yes.
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2018-05-23 14:13 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-05-23 08:35 How do I copy an element of composite type array into csv file? a <372660931@qq.com>
2018-05-23 08:41 ` amul sul <sulamul@gmail.com>
2018-05-23 08:47 ` a <372660931@qq.com>
2018-05-23 13:18 ` David G. Johnston <david.g.johnston@gmail.com>
2018-05-23 14:03 ` a <372660931@qq.com>
2018-05-23 14:13 ` David G. Johnston <david.g.johnston@gmail.com>
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