Why doesn't COPY support the HEADER options for tab-separated output?

Started by Joe Van Dykover 12 years ago9 messagesgeneral
Jump to latest
#1Joe Van Dyk
joe@tanga.com

Mostly just curious, as this is preventing me from using tab-separated
output. I'd like there to be a header in my files. I have to use CSVs
instead.

Joe

#2Bruce Momjian
bruce@momjian.us
In reply to: Joe Van Dyk (#1)
Re: Why doesn't COPY support the HEADER options for tab-separated output?

On Mon, Aug 12, 2013 at 02:15:25PM -0700, Joe Van Dyk wrote:

Mostly just curious, as this is preventing me from using tab-separated output.
I'd like there to be a header in my files. I have to use CSVs instead.

[ "this" means the fact that COPY doesn't support the HEADER option. ]

We assume CSV is going to be read into a tool that can use the header
names; delimited files don't usually have a use for those headers.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Merlin Moncure
mmoncure@gmail.com
In reply to: Bruce Momjian (#2)
Re: Why doesn't COPY support the HEADER options for tab-separated output?

On Mon, Aug 12, 2013 at 4:21 PM, Bruce Momjian <bruce@momjian.us> wrote:

On Mon, Aug 12, 2013 at 02:15:25PM -0700, Joe Van Dyk wrote:

Mostly just curious, as this is preventing me from using tab-separated output.
I'd like there to be a header in my files. I have to use CSVs instead.

[ "this" means the fact that COPY doesn't support the HEADER option. ]

We assume CSV is going to be read into a tool that can use the header
names; delimited files don't usually have a use for those headers.

that's a terrible assumption.

merlin

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4Jeff Janes
jeff.janes@gmail.com
In reply to: Bruce Momjian (#2)
Re: Why doesn't COPY support the HEADER options for tab-separated output?

On Mon, Aug 12, 2013 at 2:21 PM, Bruce Momjian <bruce@momjian.us> wrote:

On Mon, Aug 12, 2013 at 02:15:25PM -0700, Joe Van Dyk wrote:

Mostly just curious, as this is preventing me from using tab-separated output.
I'd like there to be a header in my files. I have to use CSVs instead.

[ "this" means the fact that COPY doesn't support the HEADER option. ]

We assume CSV is going to be read into a tool that can use the header
names; delimited files don't usually have a use for those headers.

There have been a few cases where I wanted this, too. I can see why
implementing it is less important than having it for CSV, but is there
a reason to consider this harmful for TEXT format? I.e. if someone
submitted a patch, would it be rejected?

Cheers,

Jeff

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#5Bruce Momjian
bruce@momjian.us
In reply to: Jeff Janes (#4)
Re: Why doesn't COPY support the HEADER options for tab-separated output?

On Mon, Aug 12, 2013 at 03:17:00PM -0700, Jeff Janes wrote:

On Mon, Aug 12, 2013 at 2:21 PM, Bruce Momjian <bruce@momjian.us> wrote:

On Mon, Aug 12, 2013 at 02:15:25PM -0700, Joe Van Dyk wrote:

Mostly just curious, as this is preventing me from using tab-separated output.
I'd like there to be a header in my files. I have to use CSVs instead.

[ "this" means the fact that COPY doesn't support the HEADER option. ]

We assume CSV is going to be read into a tool that can use the header
names; delimited files don't usually have a use for those headers.

There have been a few cases where I wanted this, too. I can see why
implementing it is less important than having it for CSV, but is there
a reason to consider this harmful for TEXT format? I.e. if someone
submitted a patch, would it be rejected?

I see no reason _not_ to support it, so sure, either we add this to 9.4,
or add it to the TODO list.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#6Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Joe Van Dyk (#1)
Re: Why doesn't COPY support the HEADER options for tab-separated output?

On 08/12/2013 02:15 PM, Joe Van Dyk wrote:

Mostly just curious, as this is preventing me from using tab-separated
output. I'd like there to be a header in my files. I have to use CSVs
instead.

I am not sure I understand. Do you mean you are converting the file to
comma separated or that you are using CSV and having to specify the
delimiter as '\t'?

Joe

--
Adrian Klaver
adrian.klaver@gmail.com

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#7Richard Huxton
dev@archonet.com
In reply to: Bruce Momjian (#5)
Re: Why doesn't COPY support the HEADER options for tab-separated output?

On 12/08/13 23:18, Bruce Momjian wrote:

On Mon, Aug 12, 2013 at 03:17:00PM -0700, Jeff Janes wrote:

On Mon, Aug 12, 2013 at 2:21 PM, Bruce Momjian <bruce@momjian.us> wrote:

On Mon, Aug 12, 2013 at 02:15:25PM -0700, Joe Van Dyk wrote:

Mostly just curious, as this is preventing me from using tab-separated output.
I'd like there to be a header in my files. I have to use CSVs instead.

Late to the discussion, but it does work to set format=csv and delimiter
= E'\t' to get tab-separated. Be nice not to have to though.

--
Richard Huxton
Archonet Ltd

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#8Bruce Momjian
bruce@momjian.us
In reply to: Richard Huxton (#7)
Re: Why doesn't COPY support the HEADER options for tab-separated output?

On Thu, Aug 15, 2013 at 09:25:07AM +0100, Richard Huxton wrote:

On 12/08/13 23:18, Bruce Momjian wrote:

On Mon, Aug 12, 2013 at 03:17:00PM -0700, Jeff Janes wrote:

On Mon, Aug 12, 2013 at 2:21 PM, Bruce Momjian <bruce@momjian.us> wrote:

On Mon, Aug 12, 2013 at 02:15:25PM -0700, Joe Van Dyk wrote:

Mostly just curious, as this is preventing me from using tab-separated output.
I'd like there to be a header in my files. I have to use CSVs instead.

Late to the discussion, but it does work to set format=csv and
delimiter = E'\t' to get tab-separated. Be nice not to have to
though.

I assume that is going to add quotes to a field that contains quotes:

CREATE TABLE test(x TEXT);
INSERT INTO test VALUES ('"a"');

COPY test TO STDOUT WITH (FORMAT CSV, DELIMITER E'\t');
"""a"""

I have added this to the TODO list:

Allow COPY "text" format to output a header

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#9Jeff Janes
jeff.janes@gmail.com
In reply to: Richard Huxton (#7)
Re: Why doesn't COPY support the HEADER options for tab-separated output?

On Thu, Aug 15, 2013 at 1:25 AM, Richard Huxton <dev@archonet.com> wrote:

On 12/08/13 23:18, Bruce Momjian wrote:

On Mon, Aug 12, 2013 at 03:17:00PM -0700, Jeff Janes wrote:

On Mon, Aug 12, 2013 at 2:21 PM, Bruce Momjian <bruce@momjian.us> wrote:

On Mon, Aug 12, 2013 at 02:15:25PM -0700, Joe Van Dyk wrote:

Mostly just curious, as this is preventing me from using tab-separated
output.
I'd like there to be a header in my files. I have to use CSVs instead.

Late to the discussion, but it does work to set format=csv and delimiter =
E'\t' to get tab-separated. Be nice not to have to though.

Also, the escaping/quoting mechanisms are different. I often find the
escapes of the TEXT format more convenient than the CSV with E'\t'.

Cheers,

Jeff

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general