Re: [GENERAL] Using window functions to get the unpaginated count for paginated queries

2012-11-14 Thread Clemens Park
Thanks for the reply everyone. In my case, it looks like there is no real drawback then, since what used to happen is: SELECT a,b,c FROM table WHERE clauses OFFSET x LIMIT y; followed by: SELECT COUNT(*) FROM ( SELECT a,b,c FROM table WHERE clauses ); (notice the lack of OFFSET and LIMIT)

Re: [GENERAL] Using window functions to get the unpaginated count for paginated queries

2012-11-14 Thread Albe Laurenz
Clemens Park wrote: > Recently, during a performance improvement sweep for an application at my company, one of the hotspots > that was discovered was pagination. > > In order to display the correct pagination links on the page, the pagination library we used (most > pagination libraries for that

[GENERAL] Using window functions to get the unpaginated count for paginated queries

2012-11-13 Thread Clemens Park
Hi all, Recently, during a performance improvement sweep for an application at my company, one of the hotspots that was discovered was pagination. In order to display the correct pagination links on the page, the pagination library we used (most pagination libraries for that matter) ran the query

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread Massa, Harald Armin
Thom, depesz, silly, > SELECT DISTINCT ON (id_bf) id_bf, wert, letztespeicherung > FROM rfmitzeit > ORDER BY id_bf, letztespeicherung ASC; yes, that does work. I put it in the real world query (my example was reduced to the relevant parts), and it provides an impressive speedup (down from 2234 to

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread Thom Brown
2009/11/20 silly > > and how would I use DISTINCT ON for this query? Please bear in mind, > > that there is more then one id_bf (just stopped the sample data with > > one of them) > > I posted the answer more than hour ago: > > SELECT DISTINCT ON (id_rf) * FROM rfmitzeit ORDER BY id_rf, > let

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread silly8888
> and how would I use DISTINCT ON for this query? Please bear in mind, > that there is more then one id_bf (just stopped the sample data with > one of them) I posted the answer more than hour ago: SELECT DISTINCT ON (id_rf) * FROM rfmitzeit ORDER BY id_rf, letztespeicherung DESC; The equivalent

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread A. Kretschmer
In response to Massa, Harald Armin : > > > Is it possible? How would the SQL utilizing WINDOW-functions look like? > > > > there is no point in using window functions in here - simply use > > "DISTINCT ON". > > and how would I use DISTINCT ON for this query? Please bear in mind, > that there is mo

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread Thom Brown
2009/11/20 Massa, Harald Armin > > > Is it possible? How would the SQL utilizing WINDOW-functions look like? > > > > there is no point in using window functions in here - simply use > > "DISTINCT ON". > > and how would I use DISTINCT ON for this query? Please bear in mind, > that there is more th

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread Massa, Harald Armin
> > Is it possible? How would the SQL utilizing WINDOW-functions look like? > > there is no point in using window functions in here - simply use > "DISTINCT ON". and how would I use DISTINCT ON for this query? Please bear in mind, that there is more then one id_bf (just stopped the sample data wit

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread A. Kretschmer
In response to hubert depesz lubaczewski : > On Fri, Nov 20, 2009 at 11:07:37AM +0100, Massa, Harald Armin wrote: > > Is it possible? How would the SQL utilizing WINDOW-functions look like? > > there is no point in using window functions in here - simply use > "DISTINCT ON". Right, but he want to

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread Thomas Kellerer
Massa, Harald Armin, 20.11.2009 11:31: no, that does not work: "id_bf";"wert";"max" 98;"blue";"2009-11-10 00:00:00" 98;"red";"2009-11-10 00:00:00" result is: I get the date of the youngest value. My expected result is: 98;"red" (that is, the entry of "wert" that is youngest) Sorry then I mi

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread hubert depesz lubaczewski
On Fri, Nov 20, 2009 at 11:07:37AM +0100, Massa, Harald Armin wrote: > Is it possible? How would the SQL utilizing WINDOW-functions look like? there is no point in using window functions in here - simply use "DISTINCT ON". Best regards, depesz -- Linkedin: http://www.linkedin.com/in/depesz /

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread silly8888
oops, I forgot the partition by. Here's the correct query: SELECT * FROM (SELECT *,row_number() OVER (PARTITION BY id_rf ORDER BY letztespeicherung DESC) FROM rfmitzeit) t WHERE row_number=1 You can also do it using SELECT DISTINCT ON: SELECT DISTINCT ON (id_rf) * FROM rfmitzeit ORDER BY id_rf,

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread silly8888
SELECT * FROM (SELECT *,row_number() OVER (ORDER BY letztespeicherung DESC) FROM rfmitzeit) t WHERE row_number=1 On Fri, Nov 20, 2009 at 5:31 AM, Massa, Harald Armin wrote: >     id_bf,  wert, letztespeicherung: >>> >>>   98,  'blue', 2009-11-09 >>>   98,  'red', 2009-11-10 >>>     now I have a

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread Massa, Harald Armin
id_bf, wert, letztespeicherung: > 98, 'blue', 2009-11-09 >> 98, 'red', 2009-11-10 >> now I have a select to get the "youngest value" for every id_bf: >> > > Not tested: > > SELECT id_bf, wert, > max(letztespeicherung) over (partition by id_bf) > FROM rfmitzeit > no, that

Re: [GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread Thomas Kellerer
Massa, Harald Armin, 20.11.2009 11:07: I have a table CREATE TABLE rfmitzeit ( id_rf inet NOT NULL, id_bf integer, wert text, letztespeicherung timestamp without time zone CONSTRAINT repofeld_id_rf PRIMARY KEY (id_rf), ); where for one id_bf there are stored mutliple values ("wert") at

[GENERAL] using window-functions to get freshest value - how?

2009-11-20 Thread Massa, Harald Armin
I have a table CREATE TABLE rfmitzeit ( id_rf inet NOT NULL, id_bf integer, wert text, letztespeicherung timestamp without time zone CONSTRAINT repofeld_id_rf PRIMARY KEY (id_rf), ); where for one id_bf there are stored mutliple values ("wert") at multiple dates: id_bf, wert, letztesp

Re: [GENERAL] using window functions

2009-03-17 Thread Daniel Manesajian
hinking my next step would be to build from source by grabbing the next daily snapshot. Is this the thing to do? Regards, Daniel > To: mane...@hotmail.com > CC: pgsql-general@postgresql.org > Subject: Re: [GENERAL] using window functions > Date: Mon, 16 Mar 2009 23:58:25 -0400

Re: [GENERAL] using window functions

2009-03-17 Thread Thomas Kellerer
Daniel Manesajian, 17.03.2009 04:33: Hi, I'm trying to get an advance taste of the window function feature that I believe is supposed to be in 8.4. I'm running 8.4devel snapshot (dated Jan-01 which seems kind of old) grabbed from the snapshot page on the postgresql website. When I try a si

Re: [GENERAL] using window functions

2009-03-16 Thread Tom Lane
Daniel Manesajian writes: > When I try a simple query "select avg(my_int) over (order by my_int rows > unbounded preceding) order by 1;" I get an error: > ERROR: syntax error at or near "over" You sure you're actually talking to the 8.4 server? Because that's exactly what you'd get if you trie

[GENERAL] using window functions

2009-03-16 Thread Daniel Manesajian
Hi, I'm trying to get an advance taste of the window function feature that I believe is supposed to be in 8.4. I'm running 8.4devel snapshot (dated Jan-01 which seems kind of old) grabbed from the snapshot page on the postgresql website. When I try a simple query "select avg(my_int) ove