Re: csv format for psql
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: Michael Paquier <michael@paquier.xyz>,
Daniel Verite <daniel@manitou-mail.org>,
PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2018-11-26T01:26:47Z
Lists: pgsql-hackers
Attachments
- psql-csv-format-v11.patch (text/x-diff) patch v11
Fabien COELHO <coelho@cri.ensmp.fr> writes: > Basically the proposed patch addresses a simple and convenient use case > which are neither addressed by \copy nor COPY. The fact that more options > are available with these commands does it precludes its usefulness as is. Yeah, I agree that this option is useful independently of whether COPY provides something similar. I think the killer argument is that right now, psql-ref.sgml repeatedly suggests that unaligned mode with fieldsep ',' is a reasonable way to produce comma-separated output for consumption by other programs. That's like handing our users a loaded foot-gun. And, in fact, right now *none* of psql's table output formats is both unambiguous and reasonably simple/popular to use. So the astonishing thing about this patch, IMO, is that we didn't do it a decade ago. I went through the documentation to improve that point, and did some other cosmetic cleanup including rebasing up to HEAD, and got the attached. I think there are two remaining points to settle: 1. Are we limiting the separator to be a single-byte character or not? If we are, the code could be made simpler and faster by working with a "char" value instead of a string. If we're not, then Michael's change needs to be undone (but I didn't do that here). I feel that if we allow multi-byte characters here, we might as well take the training wheels off and just say you can use any separator string you want, as long as it doesn't contain double quote, \r, or \n. Most programs reading a file are not going to perceive a difference between separating fields with a single multibyte character and multiple single-byte characters; either they can cope or they can't. A fair number of them are going to be in the latter category. So we can either say "do what you wish, it's your problem whether anything can read the result" or "we're going to restrict you to something that (perhaps) is more widely readable". I'm a bit inclined to the former viewpoint. If we were in the business of being restrictive, why would we allow the field separator to be changed at all? The name of the format is *comma* separated values, not something else. 2. Speaking of the field separator, I'm pretty desperately unhappy with the choice of "fieldsep_csv" as the parameter name. The trouble with that is that it encourages sticking "fieldsep_csv" in between "fieldsep" and "fieldsep_zero", because alphabet. But "fieldsep" and "fieldsep_zero" are *intimately* tied together, in fact it's only a dubious implementation choice that made them separate parameters at all. It does not make any semantic sense to stick other vaguely-related parameters in between, neither in the documentation nor in \pset output. We could avoid this self-inflicted confusion by choosing a different parameter name. I'd be good with "csv_fieldsep" or "csvfieldsep". Or we could kill both issues by hard-wiring the separator as ','. Thoughts? regards, tom lane
Commits
-
Add CSV table output mode in psql.
- aa2ba50c2c13 12.0 landed
-
Reorganize format options of psql in alphabetical order
- add9182e5908 12.0 landed
-
Complete TODO item:
- 862b20b38228 8.0.0 cited