Re: [HACKERS] [patch] A \pivot command for psql

2015-08-13 Thread Daniel Verite
David Fetter wrote: That said, a thing in psql that could slice serialized output into columns would be handy as a broad, general part of reporting in psql To avoid any confusion with server-side PIVOT, I suggest that the currently proposed command in psql should have a different name

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-11 Thread David Fetter
On Tue, Aug 11, 2015 at 10:13:48AM -0400, Robert Haas wrote: On Sun, Aug 9, 2015 at 8:18 PM, Tom Lane t...@sss.pgh.pa.us wrote: psql is a minority API, you know. Not for me. psql has already got a bunch of bells and whistles to format things in particular ways that people have wanted, and

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-11 Thread Daniel Verite
David Fetter wrote: That depends on what you mean by dynamic columns. The approach taken in the tablefunc extension is to use functions which return SETOF RECORD, which in turn need to be cast at runtime. For me, PIVOT with dynamic columns would be a pivot query whose output columns

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-11 Thread Robert Haas
On Sun, Aug 9, 2015 at 8:18 PM, Tom Lane t...@sss.pgh.pa.us wrote: psql is a minority API, you know. Not for me. psql has already got a bunch of bells and whistles to format things in particular ways that people have wanted, and I'm not really sure why the bar for this proposal should be any

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-11 Thread David Fetter
On Tue, Aug 11, 2015 at 05:13:03PM +0200, Daniel Verite wrote: David Fetter wrote: That depends on what you mean by dynamic columns. The approach taken in the tablefunc extension is to use functions which return SETOF RECORD, which in turn need to be cast at runtime. For me,

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-11 Thread Daniel Verite
David Fetter wrote: Second, if we put this feature as-is in psql, we're stuck supporting it in psql until the end of time, even if (when, I believe) we have a fuller and likely not perfectly compatible feature on the back-end. To me, doing \pivot in psql vs PIVOT in the backend is a

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-10 Thread Daniel Verite
Tom Lane wrote: I'm not sure how pushing it out to psql makes that better. There is no way to do further processing on something that psql has printed, so you've punted on solving that issue just as much if not more. It's the same spirit as \x : the only thing it achieves is better

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-10 Thread Daniel Verite
David Fetter wrote: I'm working up a proposal to add (UN)PIVOT support to the back-end. I was under the impression that a server-side PIVOT *with dynamic columns* was just unworkable as an SQL query, because it couldn't be prepared if it existed. I am wrong on that? I feel like you

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-10 Thread David Fetter
On Mon, Aug 10, 2015 at 07:10:41PM +0200, Daniel Verite wrote: David Fetter wrote: I'm working up a proposal to add (UN)PIVOT support to the back-end. I was under the impression that a server-side PIVOT *with dynamic columns* was just unworkable as an SQL query, because it couldn't

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-10 Thread Joe Conway
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 08/10/2015 04:03 PM, David Fetter wrote: I am wrong on that? I feel like you guys are all telling me that \pivot should happen on the server, but the point that it would not be realistic to begin with is not considered. I think that starting

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-10 Thread Pavel Stehule
2015-08-10 6:04 GMT+02:00 David Fetter da...@fetter.org: On Sun, Aug 09, 2015 at 07:29:40PM +0200, Daniel Verite wrote: Hi, I want to suggest a client-side \pivot command in psql, implemented in the attached patch. \pivot takes the current query in the buffer, execute it and

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-09 Thread Joe Conway
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 08/09/2015 10:37 AM, Tom Lane wrote: I can see the value of a feature like this, but doing it in psql sure seems like the wrong place. It would be unavailable to anything except interactive use. Is there a way to implement pivoting as a

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-09 Thread Tom Lane
Daniel Verite dan...@manitou-mail.org writes: I want to suggest a client-side \pivot command in psql, implemented in the attached patch. \pivot takes the current query in the buffer, execute it and display it pivoted by interpreting the result as: column1 = row in pivoted output column2 =

[HACKERS] [patch] A \pivot command for psql

2015-08-09 Thread Daniel Verite
Hi, I want to suggest a client-side \pivot command in psql, implemented in the attached patch. \pivot takes the current query in the buffer, execute it and display it pivoted by interpreting the result as: column1 = row in pivoted output column2 = column in pivoted output column3 = value at

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-09 Thread Daniel Verite
Tom Lane wrote: Is there a way to implement pivoting as a set-returning function? Not with the same ease of use. We have crosstab functions in contrib/tablefunc already, but the killer problem with PIVOT is that truly dynamic columns are never reachable directly. If we could do this:

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-09 Thread Tom Lane
Daniel Verite dan...@manitou-mail.org writes: Tom Lane wrote: Is there a way to implement pivoting as a set-returning function? Not with the same ease of use. We have crosstab functions in contrib/tablefunc already, but the killer problem with PIVOT is that truly dynamic columns are never

Re: [HACKERS] [patch] A \pivot command for psql

2015-08-09 Thread David Fetter
On Sun, Aug 09, 2015 at 07:29:40PM +0200, Daniel Verite wrote: Hi, I want to suggest a client-side \pivot command in psql, implemented in the attached patch. \pivot takes the current query in the buffer, execute it and display it pivoted by interpreting the result as: column1 = row