From: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
---|---|
To: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
Cc: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Daniel Verite <daniel(at)manitou-mail(dot)org>, Teodor Sigaev <teodor(at)sigaev(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: [patch] Proposal for \crosstabview in psql |
Date: | 2016-02-09 10:32:01 |
Message-ID: | CAEZATCVzy_Kt=EjyNrcjYDuxd1Wvz8wU0seprV0w=Cg-5LmdoA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 9 February 2016 at 10:09, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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
> query.
>
> 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
SELECT name,
to_char(date, 'mon') AS month,
sum(amount) AS amount,
extract(month from date) AS month_order
FROM invoices
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
FROM invoices
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?
Regards,
Dean
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2016-02-09 11:06:32 | Re: [patch] Proposal for \crosstabview in psql |
Previous Message | Andres Freund | 2016-02-09 10:24:35 | Re: checkpointer continuous flushing - V16 |