[GENERAL] obtain the difference between successive rows

2012-10-20 Thread ochaussavoine
Hi, I have a table 'tmvt' with a field 'created' in the row, and would like to compute the difference between successive rows. The solution I found is: It is complicate and very long to perform. The problem could be simply solved with MySql by creating a new field and updating it using a

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Raymond O'Donnell
On 20/10/2012 11:54, ochaussavoine wrote: Hi, I have a table 'tmvt' with a field 'created' in the row, and would like to compute the difference between successive rows. The solution I found is: It is complicate and very long to perform. The problem could be simply solved with MySql by

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Thalis Kalfigkopoulos
On Sat, Oct 20, 2012 at 8:02 AM, Raymond O'Donnell r...@iol.ie wrote: On 20/10/2012 11:54, ochaussavoine wrote: Hi, I have a table 'tmvt' with a field 'created' in the row, and would like to compute the difference between successive rows. The solution I found is: I think you can do it with

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Berend Tober
Thalis Kalfigkopoulos wrote: On Sat, Oct 20, 2012 at 8:02 AM, Raymond O'Donnell r...@iol.ie wrote: On 20/10/2012 11:54, ochaussavoine wrote: I have a table 'tmvt' with a field 'created' in the row, and would like to compute the difference between successive rows. The solution I found is: I

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Chris Angelico
On Sun, Oct 21, 2012 at 2:30 AM, Berend Tober bto...@broadstripe.net wrote: What about if there is more than one column you want the difference for (... coincidentally I am writing a article on this topic right now! ...), say a table which is used to record a metered quantity at not-quite

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Thalis Kalfigkopoulos
What about if there is more than one column you want the difference for (... coincidentally I am writing a article on this topic right now! ...), say a table which is used to record a metered quantity at not-quite regular intervals: CREATE TABLE electricity ( current_reading_date date,

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Berend Tober
Thalis Kalfigkopoulos wrote: SELECT current_meter_reading - lag(current_meter_reading) OVER(ORDER BY current_reading_date) AS kWh_diff, extract('days' FROM current_reading_date - lag(current_reading_date) OVER(ORDER BY current_reading_date)) as num_service_days FROM mytable; How would you get

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Raymond O'Donnell
On 20/10/2012 17:02, Berend Tober wrote: Thalis Kalfigkopoulos wrote: SELECT current_meter_reading - lag(current_meter_reading) OVER(ORDER BY current_reading_date) AS kWh_diff, extract('days' FROM current_reading_date - lag(current_reading_date) OVER(ORDER BY current_reading_date)) as

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Tom Lane
Chris Angelico ros...@gmail.com writes: To be quite honest, I would simply read the table directly and then do the processing in an application language :) But two window functions should do the trick. Whether or not it's actually more efficient that way is another question. FWIW, Postgres is

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Raymond O'Donnell
On 20/10/2012 17:23, Tom Lane wrote: Chris Angelico ros...@gmail.com writes: To be quite honest, I would simply read the table directly and then do the processing in an application language :) But two window functions should do the trick. Whether or not it's actually more efficient that way

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Berend Tober
Raymond O'Donnell wrote: On 20/10/2012 17:02, Berend Tober wrote: Thalis Kalfigkopoulos wrote: How would you get the previous reading (and perhaps the previous read date) to also appear ... Just include them in the SELECT: Well, that is surprisingly easy! How about this then: the table

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Chris Angelico
On Sun, Oct 21, 2012 at 3:29 AM, Raymond O'Donnell r...@iol.ie wrote: On 20/10/2012 17:23, Tom Lane wrote: Having said that, they are pretty expensive. I tend to agree that doing the processing on the application side might be faster --- but only if you've got a place to put such code there.

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Tom Lane
Raymond O'Donnell r...@iol.ie writes: On 20/10/2012 17:23, Tom Lane wrote: FWIW, Postgres is reasonably smart about the case of multiple window functions with identical window definitions --- once you've got one lag() in the query, adding more isn't going to cost much. Out of curiosity,

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Berend Tober
Berend Tober wrote: Raymond O'Donnell wrote: On 20/10/2012 17:02, Berend Tober wrote: Thalis Kalfigkopoulos wrote: How would you get the previous reading (and perhaps the previous read date) to also appear ... Just include them in the SELECT: Well, that is surprisingly easy! How about

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Raymond O'Donnell
On 20/10/2012 17:50, Tom Lane wrote: Raymond O'Donnell r...@iol.ie writes: On 20/10/2012 17:23, Tom Lane wrote: FWIW, Postgres is reasonably smart about the case of multiple window functions with identical window definitions --- once you've got one lag() in the query, adding more isn't going

[GENERAL] Create extension tablefunc fails with wrong ELF class: ELFCLASS32

2012-10-20 Thread Jan Mechtel
Our webhoster moved us to a 64Bit CentOS. I installed postgresql-9.1.3 from source. I run into trouble when trying to create the tablefunc extension b2blogin_mailrocket=# create extension tablefunc; ERROR: could not load library /home/b2blogin/lib/postgresql/tablefunc.so:

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Виктор Егоров
2012/10/20 Berend Tober bto...@broadstripe.net: Your suggestion almost worked as is for this, except that you have to note that reading for meter #2 and meter #3 overlap (I briefly owned two houses), and that seemed to confuse the lag() function: SELECT electric_meter_pk,

Re: [GENERAL] Create extension tablefunc fails with wrong ELF class: ELFCLASS32

2012-10-20 Thread Jeff Janes
On Sat, Oct 20, 2012 at 10:33 AM, Jan Mechtel jmech...@gmail.com wrote: Our webhoster moved us to a 64Bit CentOS. I installed postgresql-9.1.3 from source. Did you also install contrib from the same source? I run into trouble when trying to create the tablefunc extension

Re: [GENERAL] Create extension tablefunc fails with wrong ELF class: ELFCLASS32

2012-10-20 Thread Jan Mechtel
Thanks for the quick reply, This could indeed be a solution since the webhosting migrated the old folder I used for installation on 32bit. I am not very familar with linux, I'd like to ask for two clarifications: If so, you should start from a fresh source tree; or run make clean or make

Re: [GENERAL] Create extension tablefunc fails with wrong ELF class: ELFCLASS32

2012-10-20 Thread Jan Mechtel
Thanks a lot, this worked. I read to detail the tablefunc.so and then go to the postgres-9.1.3/contrib/ and call make + make install there. On 20 October 2012 20:02, Jan Mechtel jmech...@gmail.com wrote: Thanks for the quick reply, This could indeed be a solution since the webhosting migrated

Re: [GENERAL] Create extension tablefunc fails with wrong ELF class: ELFCLASS32

2012-10-20 Thread Jeff Janes
On Sat, Oct 20, 2012 at 11:00 AM, Jan Mechtel jmech...@keyrocket.com wrote: Thanks for the quick reply, This could indeed be a solution since the webhosting migrated the old folder I used for installation on 32bit. Sorry, I don't really know what this means. They just copied the folder, or

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Berend Tober
Виктор Егоров wrote: 2012/10/20 Berend Tober bto...@broadstripe.net: Your suggestion almost worked as is for this, except that you have to note that reading for meter #2 and meter #3 overlap ... You can do … OVER(PARTITION BY electric_meter_pk ORDER BY reading_date) to split you data by

[GENERAL] Create extension tablefunc fails with wrong ELF class: ELFCLASS32

2012-10-20 Thread Jan Mechtel
Our webhoster moved us to a 64Bit CentOS. I installed postgresql-9.1.3 from source. I run into trouble when trying to create the tablefunc extension b2blogin_mailrocket=# create extension tablefunc; ERROR: could not load library /home/b2blogin/lib/postgresql/tablefunc.so:

Re: [GENERAL] Create extension tablefunc fails with wrong ELF class: ELFCLASS32

2012-10-20 Thread Jan Mechtel
Thanks for the quick reply, This could indeed be a solution since the webhosting migrated the old folder I used for installation on 32bit. I am not very familar with linux, I'd like to ask for two clarifications: If so, you should start from a fresh source tree; or run make clean or make

Re: [GENERAL] obtain the difference between successive rows

2012-10-20 Thread Berend Tober
Thalis Kalfigkopoulos wrote: On Sat, Oct 20, 2012 at 8:02 AM, Raymond O'Donnell r...@iol.ie wrote: On 20/10/2012 11:54, ochaussavoine wrote: I have a table 'tmvt' with a field 'created' in the row, and would like to compute the difference between successive rows. The solution I found is: I

[GENERAL] subscribe

2012-10-20 Thread Jan Mechtel

Re: [GENERAL] Create extension tablefunc fails with wrong ELF class: ELFCLASS32

2012-10-20 Thread John R Pierce
On 10/20/12 10:21 AM, Jan Mechtel wrote: Our webhoster moved us to a 64Bit CentOS. I installed postgresql-9.1.3 from source. instead, you probably should have installed postgres from the yum.postgresql.com repository. something like this... # rpm -Uvh