On 9 February 2016 at 10:09, Pavel Stehule <pavel.steh...@gmail.com> wrote:
> The sorting on client side is necessary - minimally in one direction,
> because you cannot to create perfect sorting for both dimensions.
> Possibility to order in second dimension is just pretty comfortable -
> because you don't need to think two steps forward - when you create SQL
> I have a basic use case that should be supported well, and it is supported
> well by last version of this patch. The evaluation of syntax is subjective.
> We can compare Daniel's syntax and your proposal.
> The use case: I have a table with the invoices with attributes (date, name
> and amount). I would to take a report of amounts across months and
> customers. Horizontal dimension is month (name), vertical dimension is name
> of customers. I need sorting of months in semantic order and customers in
> alphabet order.
> So my query is:
> SELECT name, to_char(date, 'mon') AS month, extract(month from date) AS
> month_order, sum(amount) AS amount FROM invoices GROUP BY 1,2,3;
> and crosstabview command (per Daniel proposal)
> \crosstabview +name +month:month_order amount
> But if I don't need column header in human readable form, I can do
> \crosstabview +name +month_order amount
> What is solution of this use case with your proposal??
So it would just be
to_char(date, 'mon') AS month,
sum(amount) AS amount,
extract(month from date) AS month_order
GROUP BY 1,2,3
ORDER BY name
\crosstabview name month amount month_order
Note that I might also want to pass additional sort options, such as
"ORDER BY name NULLS LAST", which the existing syntax doesn't allow.
In the new syntax, such sort options could be trivially supported in
both the server- and client-side sorts:
SELECT name, to_char(date, 'mon') AS month,
extract(month from date) AS month_order, sum(amount) AS amount
GROUP BY 1,2,3
ORDER BY name NULLS LAST
\crosstabview name month amount month_order asc nulls last
This is probably not an issue in this example, but it might well be in
other cases. The +/-scol syntax is always going to be limited in what
it can support.
> I agree so this syntax is pretty raw. But it is consistent with other psql
> statements and there are not possible conflicts.
> What I mean? Your syntax is not unambiguous: \crosstabview [colV] [colH]
> [colG1[,colG2...]] [sortCol [asc|desc]] - when I would to enter sort order
> column, I have to enter one or more colG1,... or I have to enter explicitly
> asc, desc keyword.
That is resolved by the comma that precedes colG2, etc. isn't it?
Sent via pgsql-hackers mailing list (email@example.com)
To make changes to your subscription: