On 11 February 2016 at 08:43, Andres Freund <and...@anarazel.de> wrote: > On 2016-02-09 09:27:04 +0000, Dean Rasheed wrote: >> Looking at this patch, I have mixed feelings about it. On the one hand >> I really like the look of the output, and I can see that the non-fixed >> nature of the output columns makes this hard to achieve server-side. > >> But on the other hand, this seems to be going way beyond the normal >> level of result formatting that something like \x does, and I find the >> syntax for sorting particularly ugly. > > I've pretty similar doubts. Addinging features to psql which are complex > enough that it's likely that people will be forced to parse psql > output... On the other hand, a proper server side solution won't be > easy; so maybe this is a okay enough stopgap. >
Well to be clear, I like the idea of this feature, and I'm not trying to stand in the way of progressing it. However, I can't see myself committing it in its current form. My biggest problem is with the sorting, for all the reasons discussed above. There is absolutely no reason for \crosstabview to be re-sorting rows -- they should just be left in the original query result order. Sorting columns is a little more understandable, since there is no way for the original query to control the order in which the colV values come out, but Tom raises a good point -- there are far too many bells and whistles when it comes to sorting, and we don't want to be adding all of them to the psql syntax. Thinking about this some more though, perhaps *sorting* the columns is the wrong way to be thinking about it. Perhaps a better approach would be to allow the columns to be *listed* (optionally, using a separate query). Something like the following (don't get too hung up on the syntax): SELECT name, to_char(date, 'Mon') AS month, sum(amount) AS amount FROM invoices GROUP BY 1,2 ORDER BY name \crosstabview cols = (select to_char(d, 'Mon') from generate_series('2000-01-01'::date, '2000-12-01', '1 month') d) Regards, Dean -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers